Skip to content

Commit

Permalink
Merge pull request #261 from ichub/computedCSS
Browse files Browse the repository at this point in the history
Added the ability to inspect an element's style
  • Loading branch information
rickbrew committed Sep 10, 2015
2 parents a2d811f + e20d0b4 commit 93865e5
Show file tree
Hide file tree
Showing 12 changed files with 748 additions and 18 deletions.
2 changes: 1 addition & 1 deletion stetho/src/main/java/com/facebook/stetho/Stetho.java
Original file line number Diff line number Diff line change
Expand Up @@ -327,12 +327,12 @@ public DefaultInspectorModulesBuilder remove(String moduleName) {

public Iterable<ChromeDevtoolsDomain> finish() {
provideIfDesired(new Console());
provideIfDesired(new CSS());
provideIfDesired(new Debugger());
DocumentProviderFactory documentModel = resolveDocumentProvider();
if (documentModel != null) {
Document document = new Document(documentModel);
provideIfDesired(new DOM(document));
provideIfDesired(new CSS(document));
}
provideIfDesired(new DOMStorage(mContext));
provideIfDesired(new HeapProfiler());
Expand Down
4 changes: 4 additions & 0 deletions stetho/src/main/java/com/facebook/stetho/common/ListUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ public static <T> List<T> copyToImmutableList(List<T> list) {
}
}

public static <T> List<T> newImmutableList(T item) {
return new OneItemImmutableList<>(item);
}

private static interface ImmutableList<E> extends List<E>, RandomAccess {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,14 @@ public final void setAttributesAsText(Object element, String text) {
protected void onSetAttributesAsText(E element, String text) {
mSuper.setAttributesAsText(element, text);
}

@Override
@SuppressWarnings("unchecked")
public final void getStyles(Object element, StyleAccumulator accumulator) {
mSuper.getStyles(element, accumulator);
onGetStyles((E) element, accumulator);
}

protected void onGetStyles(E element, StyleAccumulator accumulator) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ public void setAttributesAsText(Object element, String text) {
mDocumentProvider.setAttributesAsText(element, text);
}

public void getElementStyles(Object element, StyleAccumulator styleAccumulator) {
NodeDescriptor nodeDescriptor = getNodeDescriptor(element);

nodeDescriptor.getStyles(element, styleAccumulator);
}

public DocumentView getDocumentView() {
verifyThreadAccess();
return mShadowDocument;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@ public interface NodeDescriptor extends ThreadBound {
void getAttributes(Object element, AttributeAccumulator attributes);

void setAttributesAsText(Object element, String text);

void getStyles(Object element, StyleAccumulator accumulator);
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,8 @@ public void getAttributes(Object element, AttributeAccumulator attributes) {
@Override
public void setAttributesAsText(Object element, String text) {
}

@Override
public void getStyles(Object element, StyleAccumulator accumulator) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

package com.facebook.stetho.inspector.elements;

import com.facebook.stetho.json.annotation.JsonValue;

public enum Origin {
INJECTED("injected"),
USER_AGENT("user-agent"),
INSPECTOR("inspector"),
REGULAR("regular");

private final String mValue;

Origin(String value) {
mValue = value;
}

@JsonValue
public String getProtocolValue() {
return mValue;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

package com.facebook.stetho.inspector.elements;

public interface StyleAccumulator {
void store(String name, String value, boolean isDefault);
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.facebook.stetho.inspector.elements.Descriptor;
import com.facebook.stetho.inspector.elements.DescriptorMap;
import com.facebook.stetho.inspector.elements.NodeType;
import com.facebook.stetho.inspector.elements.StyleAccumulator;

import javax.annotation.Nullable;

Expand Down Expand Up @@ -125,4 +126,8 @@ public View getViewForHighlighting(Object element) {

return null;
}

@Override
public void getStyles(Object element, StyleAccumulator styles) {
}
}
Loading

0 comments on commit 93865e5

Please sign in to comment.