Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(497)

Side by Side Diff: sky/engine/core/rendering/RenderObject.cpp

Issue 713073003: remove updateTouchEventTargetRectsIfNeeded (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: moar Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2000 Dirk Mueller (mueller@kde.org) 4 * (C) 2000 Dirk Mueller (mueller@kde.org)
5 * (C) 2004 Allan Sandfeld Jensen (kde@carewolf.com) 5 * (C) 2004 Allan Sandfeld Jensen (kde@carewolf.com)
6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2011 Apple Inc. All rights reserv ed. 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2011 Apple Inc. All rights reserv ed.
7 * Copyright (C) 2009 Google Inc. All rights reserved. 7 * Copyright (C) 2009 Google Inc. All rights reserved.
8 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/) 8 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/)
9 * 9 *
10 * This library is free software; you can redistribute it and/or 10 * This library is free software; you can redistribute it and/or
(...skipping 18 matching lines...) Expand all
29 29
30 #include "core/css/resolver/StyleResolver.h" 30 #include "core/css/resolver/StyleResolver.h"
31 #include "core/dom/ElementTraversal.h" 31 #include "core/dom/ElementTraversal.h"
32 #include "core/dom/StyleEngine.h" 32 #include "core/dom/StyleEngine.h"
33 #include "core/dom/shadow/ShadowRoot.h" 33 #include "core/dom/shadow/ShadowRoot.h"
34 #include "core/editing/EditingBoundary.h" 34 #include "core/editing/EditingBoundary.h"
35 #include "core/editing/FrameSelection.h" 35 #include "core/editing/FrameSelection.h"
36 #include "core/editing/htmlediting.h" 36 #include "core/editing/htmlediting.h"
37 #include "core/fetch/ResourceLoadPriorityOptimizer.h" 37 #include "core/fetch/ResourceLoadPriorityOptimizer.h"
38 #include "core/fetch/ResourceLoader.h" 38 #include "core/fetch/ResourceLoader.h"
39 #include "core/frame/EventHandlerRegistry.h"
40 #include "core/frame/FrameView.h" 39 #include "core/frame/FrameView.h"
41 #include "core/frame/LocalFrame.h" 40 #include "core/frame/LocalFrame.h"
42 #include "core/html/HTMLAnchorElement.h" 41 #include "core/html/HTMLAnchorElement.h"
43 #include "core/html/HTMLElement.h" 42 #include "core/html/HTMLElement.h"
44 #include "core/page/AutoscrollController.h" 43 #include "core/page/AutoscrollController.h"
45 #include "core/page/EventHandler.h" 44 #include "core/page/EventHandler.h"
46 #include "core/page/Page.h" 45 #include "core/page/Page.h"
47 #include "core/frame/Settings.h" 46 #include "core/frame/Settings.h"
48 #include "core/frame/UseCounter.h" 47 #include "core/frame/UseCounter.h"
49 #include "core/rendering/HitTestResult.h" 48 #include "core/rendering/HitTestResult.h"
(...skipping 1762 matching lines...) Expand 10 before | Expand all | Expand 10 after
1812 && parent() && (parent()->isRenderBlockFlow() || parent()->isRenderI nline()); 1811 && parent() && (parent()->isRenderBlockFlow() || parent()->isRenderI nline());
1813 1812
1814 // Clearing these bits is required to avoid leaving stale renderers. 1813 // Clearing these bits is required to avoid leaving stale renderers.
1815 // FIXME: We shouldn't need that hack if our logic was totally correct. 1814 // FIXME: We shouldn't need that hack if our logic was totally correct.
1816 if (diff.needsLayout()) { 1815 if (diff.needsLayout()) {
1817 clearPositionedState(); 1816 clearPositionedState();
1818 } 1817 }
1819 } else { 1818 } else {
1820 s_affectsParentBlock = false; 1819 s_affectsParentBlock = false;
1821 } 1820 }
1822
1823 // Elements with non-auto touch-action will send a SetTouchAction message
1824 // on touchstart in EventHandler::handleTouchEvent, and so effectively have
1825 // a touchstart handler that must be reported.
1826 //
1827 // Since a CSS property cannot be applied directly to a text node, a
1828 // handler will have already been added for its parent so ignore it.
1829 TouchAction oldTouchAction = m_style ? m_style->touchAction() : TouchActionA uto;
1830 if (node() && !node()->isTextNode() && (oldTouchAction == TouchActionAuto) ! = (newStyle.touchAction() == TouchActionAuto)) {
1831 EventHandlerRegistry& registry = document().frameHost()->eventHandlerReg istry();
1832 if (newStyle.touchAction() != TouchActionAuto)
1833 registry.didAddEventHandler(*node(), EventHandlerRegistry::TouchEven t);
1834 else
1835 registry.didRemoveEventHandler(*node(), EventHandlerRegistry::TouchE vent);
1836 }
1837 } 1821 }
1838 1822
1839 static bool areNonIdenticalCursorListsEqual(const RenderStyle* a, const RenderSt yle* b) 1823 static bool areNonIdenticalCursorListsEqual(const RenderStyle* a, const RenderSt yle* b)
1840 { 1824 {
1841 ASSERT(a->cursors() != b->cursors()); 1825 ASSERT(a->cursors() != b->cursors());
1842 return a->cursors() && b->cursors() && *a->cursors() == *b->cursors(); 1826 return a->cursors() && b->cursors() && *a->cursors() == *b->cursors();
1843 } 1827 }
1844 1828
1845 static inline bool areCursorsEqual(const RenderStyle* a, const RenderStyle* b) 1829 static inline bool areCursorsEqual(const RenderStyle* a, const RenderStyle* b)
1846 { 1830 {
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
2097 } 2081 }
2098 2082
2099 LayoutRect RenderObject::localCaretRect(InlineBox*, int, LayoutUnit* extraWidthT oEndOfLine) 2083 LayoutRect RenderObject::localCaretRect(InlineBox*, int, LayoutUnit* extraWidthT oEndOfLine)
2100 { 2084 {
2101 if (extraWidthToEndOfLine) 2085 if (extraWidthToEndOfLine)
2102 *extraWidthToEndOfLine = 0; 2086 *extraWidthToEndOfLine = 0;
2103 2087
2104 return LayoutRect(); 2088 return LayoutRect();
2105 } 2089 }
2106 2090
2107 void RenderObject::computeLayerHitTestRects(LayerHitTestRects& layerRects) const
2108 {
2109 // Figure out what layer our container is in. Any offset (or new layer) for this
2110 // renderer within it's container will be applied in addLayerHitTestRects.
2111 LayoutPoint layerOffset;
2112 const RenderLayer* currentLayer = 0;
2113
2114 if (!hasLayer()) {
2115 RenderObject* container = this->container();
2116 currentLayer = container->enclosingLayer();
2117 if (container && currentLayer->renderer() != container) {
2118 layerOffset.move(container->offsetFromAncestorContainer(currentLayer ->renderer()));
2119 // If the layer itself is scrolled, we have to undo the subtraction of its scroll
2120 // offset since we want the offset relative to the scrolling content , not the
2121 // element itself.
2122 if (currentLayer->renderer()->hasOverflowClip())
2123 layerOffset.move(currentLayer->renderBox()->scrolledContentOffse t());
2124 }
2125 }
2126
2127 this->addLayerHitTestRects(layerRects, currentLayer, layerOffset, LayoutRect ());
2128 }
2129
2130 void RenderObject::addLayerHitTestRects(LayerHitTestRects& layerRects, const Ren derLayer* currentLayer, const LayoutPoint& layerOffset, const LayoutRect& contai nerRect) const
2131 {
2132 ASSERT(currentLayer);
2133 ASSERT(currentLayer == this->enclosingLayer());
2134
2135 // Compute the rects for this renderer only and add them to the results.
2136 // Note that we could avoid passing the offset and instead adjust each resul t, but this
2137 // seems slightly simpler.
2138 Vector<LayoutRect> ownRects;
2139 LayoutRect newContainerRect;
2140 computeSelfHitTestRects(ownRects, layerOffset);
2141
2142 // When we get to have a lot of rects on a layer, the performance cost of tr acking those
2143 // rects outweighs the benefit of doing compositor thread hit testing.
2144 // FIXME: This limit needs to be low due to the O(n^2) algorithm in
2145 // WebLayer::setTouchEventHandlerRegion - crbug.com/300282.
2146 const size_t maxRectsPerLayer = 100;
2147
2148 LayerHitTestRects::iterator iter = layerRects.find(currentLayer);
2149 Vector<LayoutRect>* iterValue;
2150 if (iter == layerRects.end())
2151 iterValue = &layerRects.add(currentLayer, Vector<LayoutRect>()).storedVa lue->value;
2152 else
2153 iterValue = &iter->value;
2154 for (size_t i = 0; i < ownRects.size(); i++) {
2155 if (!containerRect.contains(ownRects[i])) {
2156 iterValue->append(ownRects[i]);
2157 if (iterValue->size() > maxRectsPerLayer) {
2158 // Just mark the entire layer instead, and switch to walking the layer
2159 // tree instead of the render tree.
2160 layerRects.remove(currentLayer);
2161 currentLayer->addLayerHitTestRects(layerRects);
2162 return;
2163 }
2164 if (newContainerRect.isEmpty())
2165 newContainerRect = ownRects[i];
2166 }
2167 }
2168 if (newContainerRect.isEmpty())
2169 newContainerRect = containerRect;
2170
2171 // If it's possible for children to have rects outside our bounds, then we n eed to descend into
2172 // the children and compute them.
2173 // Ideally there would be other cases where we could detect that children co uldn't have rects
2174 // outside our bounds and prune the tree walk.
2175 // Note that we don't use Region here because Union is O(N) - better to just keep a list of
2176 // partially redundant rectangles. If we find examples where this is expensi ve, then we could
2177 // rewrite Region to be more efficient. See https://bugs.webkit.org/show_bug .cgi?id=100814.
2178 if (!isRenderView()) {
2179 for (RenderObject* curr = slowFirstChild(); curr; curr = curr->nextSibli ng()) {
2180 curr->addLayerHitTestRects(layerRects, currentLayer, layerOffset, n ewContainerRect);
2181 }
2182 }
2183 }
2184
2185 bool RenderObject::isRooted() const 2091 bool RenderObject::isRooted() const
2186 { 2092 {
2187 const RenderObject* object = this; 2093 const RenderObject* object = this;
2188 while (object->parent() && !object->hasLayer()) 2094 while (object->parent() && !object->hasLayer())
2189 object = object->parent(); 2095 object = object->parent();
2190 if (object->hasLayer()) 2096 if (object->hasLayer())
2191 return toRenderLayerModelObject(object)->layer()->root()->isRootLayer(); 2097 return toRenderLayerModelObject(object)->layer()->root()->isRootLayer();
2192 return false; 2098 return false;
2193 } 2099 }
2194 2100
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
2275 children->destroyLeftoverChildren(); 2181 children->destroyLeftoverChildren();
2276 2182
2277 // If this renderer is being autoscrolled, stop the autoscrolling. 2183 // If this renderer is being autoscrolled, stop the autoscrolling.
2278 if (LocalFrame* frame = this->frame()) { 2184 if (LocalFrame* frame = this->frame()) {
2279 if (frame->page()) 2185 if (frame->page())
2280 frame->page()->autoscrollController().stopAutoscrollIfNeeded(this); 2186 frame->page()->autoscrollController().stopAutoscrollIfNeeded(this);
2281 } 2187 }
2282 2188
2283 remove(); 2189 remove();
2284 2190
2285 // Remove the handler if node had touch-action set. Don't call when
2286 // document is being destroyed as all handlers will have been cleared
2287 // previously. Handlers are not added for text nodes so don't try removing
2288 // for one too. Need to check if m_style is null in cases of partial constru ction.
2289 if (!documentBeingDestroyed() && node() && !node()->isTextNode() && m_style && m_style->touchAction() != TouchActionAuto)
2290 document().frameHost()->eventHandlerRegistry().didRemoveEventHandler(*no de(), EventHandlerRegistry::TouchEvent);
2291
2292 setAncestorLineBoxDirty(false); 2191 setAncestorLineBoxDirty(false);
2293 2192
2294 clearLayoutRootIfNeeded(); 2193 clearLayoutRootIfNeeded();
2295 } 2194 }
2296 2195
2297 void RenderObject::insertedIntoTree() 2196 void RenderObject::insertedIntoTree()
2298 { 2197 {
2299 // FIXME: We should ASSERT(isRooted()) here but generated content makes some out-of-order insertion. 2198 // FIXME: We should ASSERT(isRooted()) here but generated content makes some out-of-order insertion.
2300 2199
2301 // Keep our layer hierarchy updated. Optimize for the common case where we d on't have any children 2200 // Keep our layer hierarchy updated. Optimize for the common case where we d on't have any children
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after
2812 { 2711 {
2813 if (object1) { 2712 if (object1) {
2814 const blink::RenderObject* root = object1; 2713 const blink::RenderObject* root = object1;
2815 while (root->parent()) 2714 while (root->parent())
2816 root = root->parent(); 2715 root = root->parent();
2817 root->showRenderTreeAndMark(object1, "*", object2, "-", 0); 2716 root->showRenderTreeAndMark(object1, "*", object2, "-", 0);
2818 } 2717 }
2819 } 2718 }
2820 2719
2821 #endif 2720 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698