Changeset 214483 in webkit
- Timestamp:
- Mar 28, 2017, 11:29:40 AM (9 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 2 edited
-
ChangeLog (modified) (1 diff)
-
page/DebugPageOverlays.cpp (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r214482 r214483 1 2017-03-27 Simon Fraser <simon.fraser@apple.com> 2 3 Enhance the touch region debug overlay to show regions for the different events 4 https://bugs.webkit.org/show_bug.cgi?id=170162 5 6 Reviewed by Tim Horton. 7 8 Have NonFastScrollableRegionOverlay use a different color for each region in EventTrackingRegions, 9 and to draw a legend showing what the colors mean. 10 11 On Mac, this overlay displays the non-fast scrollable region (which we don't keep separate from the wheel event 12 region). 13 14 * page/DebugPageOverlays.cpp: 15 (WebCore::NonFastScrollableRegionOverlay::updateRegion): 16 (WebCore::touchEventRegionColors): 17 (WebCore::drawRightAlignedText): 18 (WebCore::NonFastScrollableRegionOverlay::drawRect): 19 (WebCore::RegionOverlay::drawRect): 20 (WebCore::RegionOverlay::drawRegion): 21 1 22 2017-03-27 Simon Fraser <simon.fraser@apple.com> 2 23 -
trunk/Source/WebCore/page/DebugPageOverlays.cpp
r211033 r214483 56 56 void willMoveToPage(PageOverlay&, Page*) final; 57 57 void didMoveToPage(PageOverlay&, Page*) final; 58 void drawRect(PageOverlay&, GraphicsContext&, const IntRect& dirtyRect) final;58 void drawRect(PageOverlay&, GraphicsContext&, const IntRect& dirtyRect) override; 59 59 bool mouseEvent(PageOverlay&, const PlatformMouseEvent&) final; 60 60 void didScrollFrame(PageOverlay&, Frame&) final; … … 63 63 // Returns true if the region changed. 64 64 virtual bool updateRegion() = 0; 65 void drawRegion(GraphicsContext&, const Region&, const Color&, const IntRect& dirtyRect); 65 66 66 67 MainFrame& m_frame; … … 120 121 121 122 bool updateRegion() override; 123 void drawRect(PageOverlay&, GraphicsContext&, const IntRect& dirtyRect) final; 124 125 EventTrackingRegions m_eventTrackingRegions; 122 126 }; 123 127 124 128 bool NonFastScrollableRegionOverlay::updateRegion() 125 129 { 126 auto region = std::make_unique<Region>();130 bool regionChanged = false; 127 131 128 132 if (Page* page = m_frame.page()) { 129 133 if (ScrollingCoordinator* scrollingCoordinator = page->scrollingCoordinator()) { 130 134 EventTrackingRegions eventTrackingRegions = scrollingCoordinator->absoluteEventTrackingRegions(); 131 for (const auto& synchronousEventRegion : eventTrackingRegions.eventSpecificSynchronousDispatchRegions) 132 region->unite(synchronousEventRegion.value); 135 136 if (eventTrackingRegions != m_eventTrackingRegions) { 137 m_eventTrackingRegions = eventTrackingRegions; 138 regionChanged = true; 139 } 133 140 } 134 141 } 135 142 136 bool regionChanged = !m_region || !(*m_region == *region);137 m_region = WTFMove(region);138 143 return regionChanged; 144 } 145 146 static HashMap<String, Color>& touchEventRegionColors() 147 { 148 static NeverDestroyed<HashMap<String, Color>> regionColors; 149 150 if (regionColors.get().isEmpty()) { 151 regionColors.get().add("touchstart", Color(191, 191, 63, 80)); 152 regionColors.get().add("touchmove", Color(63, 191, 191, 80)); 153 regionColors.get().add("touchend", Color(191, 63, 127, 80)); 154 regionColors.get().add("touchforcechange", Color(63, 63, 191, 80)); 155 regionColors.get().add("wheel", Color(255, 128, 0, 80)); 156 } 157 158 return regionColors; 159 } 160 161 static void drawRightAlignedText(const String& text, GraphicsContext& context, const FontCascade& font, const FloatPoint& boxLocation) 162 { 163 float textGap = 10; 164 float textBaselineFromTop = 14; 165 166 TextRun textRun = TextRun(StringView(text)); 167 context.setFillColor(Color::transparent); 168 float textWidth = context.drawText(font, textRun, { }); 169 context.setFillColor(Color::black); 170 context.drawText(font, textRun, boxLocation + FloatSize(-(textWidth + textGap), textBaselineFromTop)); 171 } 172 173 void NonFastScrollableRegionOverlay::drawRect(PageOverlay& pageOverlay, GraphicsContext& context, const IntRect&) 174 { 175 IntRect bounds = pageOverlay.bounds(); 176 177 context.clearRect(bounds); 178 179 FloatRect legendRect = { bounds.maxX() - 30.0f, 10, 20, 20 }; 180 181 FontCascadeDescription fontDescription; 182 fontDescription.setOneFamily("Helvetica"); 183 fontDescription.setSpecifiedSize(12); 184 fontDescription.setComputedSize(12); 185 fontDescription.setWeight(FontSelectionValue(500)); 186 FontCascade font(fontDescription, 0, 0); 187 font.update(nullptr); 188 189 #if ENABLE(TOUCH_EVENTS) 190 context.setFillColor(touchEventRegionColors().get("touchstart")); 191 context.fillRect(legendRect); 192 drawRightAlignedText("touchstart", context, font, legendRect.location()); 193 194 legendRect.move(0, 30); 195 context.setFillColor(touchEventRegionColors().get("touchmove")); 196 context.fillRect(legendRect); 197 drawRightAlignedText("touchmove", context, font, legendRect.location()); 198 199 legendRect.move(0, 30); 200 context.setFillColor(touchEventRegionColors().get("touchend")); 201 context.fillRect(legendRect); 202 drawRightAlignedText("touchend", context, font, legendRect.location()); 203 204 legendRect.move(0, 30); 205 context.setFillColor(touchEventRegionColors().get("touchforcechange")); 206 context.fillRect(legendRect); 207 drawRightAlignedText("touchforcechange", context, font, legendRect.location()); 208 209 legendRect.move(0, 30); 210 context.setFillColor(m_color); 211 context.fillRect(legendRect); 212 drawRightAlignedText("passive listeners", context, font, legendRect.location()); 213 #else 214 // On desktop platforms, the "wheel" region includes the non-fast scrollable region. 215 context.setFillColor(touchEventRegionColors().get("wheel")); 216 context.fillRect(legendRect); 217 drawRightAlignedText("non-fast region", context, font, legendRect.location()); 218 #endif 219 220 for (const auto& synchronousEventRegion : m_eventTrackingRegions.eventSpecificSynchronousDispatchRegions) { 221 Color regionColor = touchEventRegionColors().get(synchronousEventRegion.key); 222 drawRegion(context, synchronousEventRegion.value, regionColor, bounds); 223 } 224 225 drawRegion(context, m_eventTrackingRegions.asynchronousDispatchRegion, m_color, bounds); 139 226 } 140 227 … … 183 270 return; 184 271 272 drawRegion(context, *m_region, m_color, dirtyRect); 273 } 274 275 void RegionOverlay::drawRegion(GraphicsContext& context, const Region& region, const Color& color, const IntRect& dirtyRect) 276 { 185 277 GraphicsContextStateSaver saver(context); 186 context.setFillColor( m_color);187 for (auto rect : m_region->rects()) {278 context.setFillColor(color); 279 for (auto rect : region.rects()) { 188 280 if (rect.intersects(dirtyRect)) 189 281 context.fillRect(rect);
Note:
See TracChangeset
for help on using the changeset viewer.