Changeset 238570 in webkit
- Timestamp:
- Nov 27, 2018 1:16:07 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 3 added
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r238566 r238570 1 2018-11-27 Timothy Hatcher <timothy@apple.com> 2 3 Web Inspector: Add support for forcing color scheme appearance in DOM tree. 4 https://bugs.webkit.org/show_bug.cgi?id=191820 5 rdar://problem/46153172 6 7 Reviewed by Devin Rousso. 8 9 * TestExpectations: Skip dark mode tests on other platforms. 10 * inspector/css/force-page-appearance-expected.txt: Added. 11 * inspector/css/force-page-appearance.html: Added. 12 * platform/mac/TestExpectations: Expect dark mode tests to pass on Mojave and later. 13 1 14 2018-11-27 Tim Horton <timothy_horton@apple.com> 2 15 -
trunk/LayoutTests/TestExpectations
r238545 r238570 75 75 76 76 # Only applicable on macOS 77 css-dark-mode [ Skip ] 77 78 fast/css/apple-system-control-colors.html [ Skip ] 79 inspector/css/force-page-appearance.html [ Skip ] 78 80 79 81 # Only Mac supports force tests. -
trunk/LayoutTests/platform/mac/TestExpectations
r238457 r238570 1769 1769 1770 1770 # Dark Mode is Mojave and later. 1771 [ Sierra HighSierra ] css-dark-mode [ Skip ] 1771 [ Mojave+ ] css-dark-mode [ Pass ] 1772 [ Mojave+ ] inspector/css/force-page-appearance.html [ Pass ] 1772 1773 1773 1774 webkit.org/b/185651 legacy-animation-engine/animations/play-state-in-shorthand.html [ Pass Failure ] -
trunk/Source/JavaScriptCore/ChangeLog
r238568 r238570 1 2018-11-27 Timothy Hatcher <timothy@apple.com> 2 3 Web Inspector: Add support for forcing color scheme appearance in DOM tree. 4 https://bugs.webkit.org/show_bug.cgi?id=191820 5 rdar://problem/46153172 6 7 Reviewed by Devin Rousso. 8 9 * inspector/protocol/Page.json: Added setForcedAppearance. 10 Also added the defaultAppearanceDidChange event and Appearance enum. 11 1 12 2018-11-27 Ryan Haddad <ryanhaddad@apple.com> 2 13 -
trunk/Source/JavaScriptCore/inspector/protocol/Page.json
r232318 r238570 21 21 "enum": ["None", "Lax", "Strict"], 22 22 "description": "Same-Site policy of a cookie." 23 }, 24 { 25 "id": "Appearance", 26 "type": "string", 27 "enum": ["Light", "Dark"], 28 "description": "Page appearance name." 23 29 }, 24 30 { … … 195 201 }, 196 202 { 203 "name": "setForcedAppearance", 204 "description": "Forces the given appearance for the page.", 205 "parameters": [ 206 { "name": "appearance", "$ref": "Appearance", "description": "Appearance name to force. Empty string disables the override." } 207 ] 208 }, 209 { 197 210 "name": "getCompositingBordersVisible", 198 211 "description": "Indicates the visibility of compositing borders.", … … 295 308 { "name": "frameId", "$ref": "Network.FrameId", "description": "Id of the frame that has cleared its scheduled navigation." } 296 309 ] 310 }, 311 { 312 "name": "defaultAppearanceDidChange", 313 "description": "Fired when page's default appearance changes, even if there is a forced appearance.", 314 "parameters": [ 315 { "name": "appearance", "$ref": "Appearance", "description": "Name of the appearance that is active (not considering any forced appearance.)" } 316 ] 297 317 } 298 318 ] -
trunk/Source/WebCore/ChangeLog
r238566 r238570 1 2018-11-27 Timothy Hatcher <timothy@apple.com> 2 3 Web Inspector: Add support for forcing color scheme appearance in DOM tree. 4 https://bugs.webkit.org/show_bug.cgi?id=191820 5 rdar://problem/46153172 6 7 Reviewed by Devin Rousso. 8 9 Test: inspector/css/force-page-appearance.html 10 11 * inspector/InspectorInstrumentation.cpp: 12 (WebCore::InspectorInstrumentation::defaultAppearanceDidChangeImpl): 13 * inspector/InspectorInstrumentation.h: 14 (WebCore::InspectorInstrumentation::defaultAppearanceDidChange): 15 * inspector/agents/InspectorPageAgent.cpp: 16 (WebCore::InspectorPageAgent::enable): Fire defaultAppearanceDidChange() on macOS Majave. 17 (WebCore::InspectorPageAgent::disable): Call setForcedAppearance() with empty string. 18 (WebCore::InspectorPageAgent::defaultAppearanceDidChange): Added. 19 (WebCore::InspectorPageAgent::setForcedAppearance): Added. 20 * inspector/agents/InspectorPageAgent.h: 21 * page/Page.cpp: 22 (WebCore::Page::setUseDarkAppearance): Call InspectorInstrumentation::defaultAppearanceDidChange(). 23 (WebCore::Page::useDarkAppearance const): Return override value if not nullopt. 24 (WebCore::Page::setUseDarkAppearanceOverride): Added. 25 * page/Page.h: 26 (WebCore::Page::defaultUseDarkAppearance const): Added. 27 1 28 2018-11-27 Tim Horton <timothy_horton@apple.com> 2 29 -
trunk/Source/WebCore/inspector/InspectorInstrumentation.cpp
r237431 r238570 783 783 } 784 784 785 void InspectorInstrumentation::defaultAppearanceDidChangeImpl(InstrumentingAgents& instrumentingAgents, bool useDarkAppearance) 786 { 787 if (InspectorPageAgent* inspectorPageAgent = instrumentingAgents.inspectorPageAgent()) 788 inspectorPageAgent->defaultAppearanceDidChange(useDarkAppearance); 789 } 790 785 791 void InspectorInstrumentation::willDestroyCachedResourceImpl(CachedResource& cachedResource) 786 792 { -
trunk/Source/WebCore/inspector/InspectorInstrumentation.h
r237431 r238570 214 214 static void frameScheduledNavigation(Frame&, Seconds delay); 215 215 static void frameClearedScheduledNavigation(Frame&); 216 static void defaultAppearanceDidChange(Page&, bool useDarkAppearance); 216 217 static void willDestroyCachedResource(CachedResource&); 217 218 … … 387 388 static void frameScheduledNavigationImpl(InstrumentingAgents&, Frame&, Seconds delay); 388 389 static void frameClearedScheduledNavigationImpl(InstrumentingAgents&, Frame&); 390 static void defaultAppearanceDidChangeImpl(InstrumentingAgents&, bool useDarkAppearance); 389 391 static void willDestroyCachedResourceImpl(CachedResource&); 390 392 … … 1136 1138 } 1137 1139 1140 inline void InspectorInstrumentation::defaultAppearanceDidChange(Page& page, bool useDarkAppearance) 1141 { 1142 FAST_RETURN_IF_NO_FRONTENDS(void()); 1143 defaultAppearanceDidChangeImpl(instrumentingAgentsForPage(page), useDarkAppearance); 1144 } 1145 1138 1146 inline void InspectorInstrumentation::willDestroyCachedResource(CachedResource& cachedResource) 1139 1147 { -
trunk/Source/WebCore/inspector/agents/InspectorPageAgent.cpp
r236762 r238570 301 301 stopwatch->reset(); 302 302 stopwatch->start(); 303 304 #if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400 305 defaultAppearanceDidChange(m_page.defaultUseDarkAppearance()); 306 #endif 303 307 } 304 308 … … 311 315 setShowPaintRects(unused, false); 312 316 setEmulatedMedia(unused, emptyString()); 317 setForcedAppearance(unused, emptyString()); 313 318 } 314 319 … … 684 689 { 685 690 m_frontendDispatcher->frameClearedScheduledNavigation(frameId(&frame)); 691 } 692 693 void InspectorPageAgent::defaultAppearanceDidChange(bool useDarkAppearance) 694 { 695 m_frontendDispatcher->defaultAppearanceDidChange(useDarkAppearance ? Inspector::Protocol::Page::Appearance::Dark : Inspector::Protocol::Page::Appearance::Light); 686 696 } 687 697 … … 809 819 } 810 820 821 void InspectorPageAgent::setForcedAppearance(ErrorString&, const String& appearance) 822 { 823 if (appearance == m_forcedAppearance) 824 return; 825 826 m_forcedAppearance = appearance; 827 828 if (appearance == "Light"_s) 829 m_page.setUseDarkAppearanceOverride(false); 830 else if (appearance == "Dark"_s) 831 m_page.setUseDarkAppearanceOverride(true); 832 else 833 m_page.setUseDarkAppearanceOverride(std::nullopt); 834 } 835 811 836 void InspectorPageAgent::applyEmulatedMedia(String& media) 812 837 { -
trunk/Source/WebCore/inspector/agents/InspectorPageAgent.h
r231881 r238570 101 101 void setShowPaintRects(ErrorString&, bool show) final; 102 102 void setEmulatedMedia(ErrorString&, const String&) final; 103 void setForcedAppearance(ErrorString&, const String&) final; 103 104 void getCompositingBordersVisible(ErrorString&, bool* out_param) final; 104 105 void setCompositingBordersVisible(ErrorString&, bool) final; … … 117 118 void frameScheduledNavigation(Frame&, Seconds delay); 118 119 void frameClearedScheduledNavigation(Frame&); 120 void defaultAppearanceDidChange(bool useDarkAppearance); 119 121 void applyEmulatedMedia(String&); 120 122 void didPaint(RenderObject&, const LayoutRect&); … … 161 163 bool m_showPaintRects { false }; 162 164 String m_emulatedMedia; 165 String m_forcedAppearance; 163 166 }; 164 167 -
trunk/Source/WebCore/page/Page.cpp
r238463 r238570 2633 2633 m_useDarkAppearance = value; 2634 2634 2635 InspectorInstrumentation::defaultAppearanceDidChange(*this, value); 2636 2635 2637 appearanceDidChange(); 2636 2638 } … … 2641 2643 if (!view || !equalLettersIgnoringASCIICase(view->mediaType(), "screen")) 2642 2644 return false; 2645 if (m_useDarkAppearanceOverride) 2646 return m_useDarkAppearanceOverride.value(); 2643 2647 return m_useDarkAppearance; 2648 } 2649 2650 void Page::setUseDarkAppearanceOverride(std::optional<bool> valueOverride) 2651 { 2652 if (valueOverride == m_useDarkAppearanceOverride) 2653 return; 2654 2655 m_useDarkAppearanceOverride = valueOverride; 2656 2657 appearanceDidChange(); 2644 2658 } 2645 2659 -
trunk/Source/WebCore/page/Page.h
r238454 r238570 361 361 WEBCORE_EXPORT bool useDarkAppearance() const; 362 362 WEBCORE_EXPORT void setUseDarkAppearance(bool); 363 bool defaultUseDarkAppearance() const { return m_useDarkAppearance; } 364 void setUseDarkAppearanceOverride(std::optional<bool>); 363 365 364 366 #if ENABLE(TEXT_AUTOSIZING) … … 794 796 bool m_useSystemAppearance { false }; 795 797 bool m_useDarkAppearance { false }; 798 std::optional<bool> m_useDarkAppearanceOverride; 796 799 797 800 #if ENABLE(TEXT_AUTOSIZING) -
trunk/Source/WebInspectorUI/ChangeLog
r238569 r238570 1 2018-11-27 Timothy Hatcher <timothy@apple.com> 2 3 Web Inspector: Add support for forcing color scheme appearance in DOM tree. 4 https://bugs.webkit.org/show_bug.cgi?id=191820 5 rdar://problem/46153172 6 7 Reviewed by Devin Rousso. 8 9 * Localizations/en.lproj/localizedStrings.js: Updated. 10 * UserInterface/Controllers/CSSManager.js: 11 (WI.CSSManager): 12 (WI.CSSManager.prototype.get defaultAppearance): Added. 13 (WI.CSSManager.prototype.get forcedAppearance): Added. 14 (WI.CSSManager.prototype.set forcedAppearance): Added. 15 (WI.CSSManager.prototype.canForceAppearance): Added. 16 (WI.CSSManager.prototype.defaultAppearanceDidChange): Added. 17 * UserInterface/Images/Appearance.svg: Added. 18 * UserInterface/Protocol/PageObserver.js: 19 (WI.PageObserver.prototype.defaultAppearanceChanged): Added. 20 * UserInterface/Views/DOMTreeContentView.js: 21 (WI.DOMTreeContentView): 22 (WI.DOMTreeContentView.prototype.get navigationItems): 23 (WI.DOMTreeContentView.prototype._defaultAppearanceDidChange): Added. 24 (WI.DOMTreeContentView.prototype._toggleAppearance): Added. 25 1 26 2018-11-27 Matt Baker <mattbaker@apple.com> 2 27 -
trunk/Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js
r238502 r238570 419 419 localizedStrings["Font"] = "Font"; 420 420 localizedStrings["Fonts"] = "Fonts"; 421 localizedStrings["Force Dark Appearance"] = "Force Dark Appearance"; 422 localizedStrings["Force Light Appearance"] = "Force Light Appearance"; 421 423 localizedStrings["Force Print Media Styles"] = "Force Print Media Styles"; 422 424 localizedStrings["Forced Layout"] = "Forced Layout"; … … 982 984 localizedStrings["Unsupported property value"] = "Unsupported property value"; 983 985 localizedStrings["Untitled"] = "Untitled"; 986 localizedStrings["Use Default Appearance"] = "Use Default Appearance"; 984 987 localizedStrings["Use Default Media Styles"] = "Use Default Media Styles"; 985 988 localizedStrings["Use the resource cache when loading resources"] = "Use the resource cache when loading resources"; -
trunk/Source/WebInspectorUI/UserInterface/Controllers/CSSManager.js
r238048 r238570 46 46 this._styleSheetFrameURLMap = new Map; 47 47 this._nodeStylesMap = {}; 48 this._defaultAppearance = null; 49 this._forcedAppearance = null; 48 50 49 51 // COMPATIBILITY (iOS 9): Legacy backends did not send stylesheet … … 108 110 } 109 111 112 get defaultAppearance() 113 { 114 return this._defaultAppearance; 115 } 116 117 get forcedAppearance() 118 { 119 return this._forcedAppearance; 120 } 121 122 set forcedAppearance(name) 123 { 124 if (!this.canForceAppearance()) 125 return; 126 127 let protocolName = ""; 128 129 switch (name) { 130 case WI.CSSManager.Appearance.Light: 131 protocolName = PageAgent.Appearance.Light; 132 break; 133 134 case WI.CSSManager.Appearance.Dark: 135 protocolName = PageAgent.Appearance.Dark; 136 break; 137 138 case null: 139 case undefined: 140 case "": 141 protocolName = ""; 142 break; 143 144 default: 145 // Abort for unknown values. 146 return; 147 } 148 149 this._forcedAppearance = name || null; 150 151 PageAgent.setForcedAppearance(protocolName).then(() => { 152 this.mediaQueryResultChanged(); 153 this.dispatchEventToListeners(WI.CSSManager.Event.ForcedAppearanceDidChange, {appearance: this._forcedAppearance}); 154 }); 155 } 156 157 canForceAppearance() 158 { 159 return window.PageAgent && !!PageAgent.setForcedAppearance && this._defaultAppearance; 160 } 161 110 162 canForcePseudoClasses() 111 163 { … … 270 322 } 271 323 324 defaultAppearanceDidChange(protocolName) 325 { 326 // Called from WI.PageObserver. 327 328 let appearance = null; 329 330 switch (protocolName) { 331 case PageAgent.Appearance.Light: 332 appearance = WI.CSSManager.Appearance.Light; 333 break; 334 335 case PageAgent.Appearance.Dark: 336 appearance = WI.CSSManager.Appearance.Dark; 337 break; 338 339 default: 340 console.error("Unknown default appearance name:", protocolName); 341 break; 342 } 343 344 this._defaultAppearance = appearance; 345 346 this.mediaQueryResultChanged(); 347 348 this.dispatchEventToListeners(WI.CSSManager.Event.DefaultAppearanceDidChange, {appearance}); 349 } 350 272 351 // Protected 273 352 … … 562 641 StyleSheetAdded: "css-manager-style-sheet-added", 563 642 StyleSheetRemoved: "css-manager-style-sheet-removed", 643 DefaultAppearanceDidChange: "css-manager-default-appearance-did-change", 644 ForcedAppearanceDidChange: "css-manager-forced-appearance-did-change", 645 }; 646 647 WI.CSSManager.Appearance = { 648 Light: Symbol("light"), 649 Dark: Symbol("dark"), 564 650 }; 565 651 -
trunk/Source/WebInspectorUI/UserInterface/Protocol/PageObserver.js
r236766 r238570 48 48 } 49 49 50 defaultAppearanceDidChange(appearance) 51 { 52 WI.cssManager.defaultAppearanceDidChange(appearance); 53 } 54 50 55 frameStartedLoading(frameId) 51 56 { -
trunk/Source/WebInspectorUI/UserInterface/Views/DOMTreeContentView.js
r238048 r238570 75 75 WI.domManager.addEventListener(WI.DOMManager.Event.CharacterDataModified, this._domNodeChanged, this); 76 76 77 WI.cssManager.addEventListener(WI.CSSManager.Event.DefaultAppearanceDidChange, this._defaultAppearanceDidChange, this); 78 77 79 this._lastSelectedNodePathSetting = new WI.Setting("last-selected-node-path", null); 78 80 … … 82 84 this._pendingBreakpointNodeIdentifiers = new Set; 83 85 86 if (WI.cssManager.canForceAppearance()) 87 this._defaultAppearanceDidChange(); 88 84 89 if (WI.domDebuggerManager.supported) { 85 90 WI.debuggerManager.addEventListener(WI.DebuggerManager.Event.BreakpointsEnabledDidChange, this._breakpointsEnabledDidChange, this); … … 100 105 { 101 106 let items = [this._showPrintStylesButtonNavigationItem, this._showsShadowDOMButtonNavigationItem]; 107 108 if (this._forceAppearanceButtonNavigationItem) 109 items.unshift(this._forceAppearanceButtonNavigationItem); 102 110 103 111 // COMPATIBILITY (iOS 11.3) … … 583 591 } 584 592 593 _defaultAppearanceDidChange() 594 { 595 let defaultAppearance = WI.cssManager.defaultAppearance; 596 if (!defaultAppearance) { 597 this._lastKnownDefaultAppearance = null; 598 this._forceAppearanceButtonNavigationItem = null; 599 this.dispatchEventToListeners(WI.ContentView.Event.NavigationItemsDidChange); 600 return; 601 } 602 603 // Don't update the navigation item if there is currently a forced appearance. 604 // The user will need to toggle it off to update it based on the new default appearance. 605 if (WI.cssManager.forcedAppearance && this._forceAppearanceButtonNavigationItem) 606 return; 607 608 this._forceAppearanceButtonNavigationItem = null; 609 610 switch (defaultAppearance) { 611 case WI.CSSManager.Appearance.Light: 612 this._forceAppearanceButtonNavigationItem = new WI.ActivateButtonNavigationItem("appearance", WI.UIString("Force Dark Appearance"), WI.UIString("Use Default Appearance"), "Images/Appearance.svg", 16, 16); 613 break; 614 case WI.CSSManager.Appearance.Dark: 615 this._forceAppearanceButtonNavigationItem = new WI.ActivateButtonNavigationItem("appearance", WI.UIString("Force Light Appearance"), WI.UIString("Use Default Appearance"), "Images/Appearance.svg", 16, 16); 616 break; 617 } 618 619 if (!this._forceAppearanceButtonNavigationItem) { 620 console.error("Unknown default appearance name:", defaultAppearance); 621 this.dispatchEventToListeners(WI.ContentView.Event.NavigationItemsDidChange); 622 return; 623 } 624 625 this._lastKnownDefaultAppearance = defaultAppearance; 626 627 this._forceAppearanceButtonNavigationItem.addEventListener(WI.ButtonNavigationItem.Event.Clicked, this._toggleAppearance, this); 628 this._forceAppearanceButtonNavigationItem.visibilityPriority = WI.NavigationItem.VisibilityPriority.Low; 629 this._forceAppearanceButtonNavigationItem.activated = !!WI.cssManager.forcedAppearance; 630 631 this.dispatchEventToListeners(WI.ContentView.Event.NavigationItemsDidChange); 632 } 633 634 _toggleAppearance(event) 635 { 636 // Use the last known default appearance, since that is the appearance this navigation item was generated for. 637 let appearanceToForce = null; 638 switch (this._lastKnownDefaultAppearance) { 639 case WI.CSSManager.Appearance.Light: 640 appearanceToForce = WI.CSSManager.Appearance.Dark; 641 break; 642 case WI.CSSManager.Appearance.Dark: 643 appearanceToForce = WI.CSSManager.Appearance.Light; 644 break; 645 } 646 647 console.assert(appearanceToForce); 648 WI.cssManager.forcedAppearance = WI.cssManager.forcedAppearance == appearanceToForce ? null : appearanceToForce; 649 650 // When no longer forcing an appearance, if the last known default appearance is different than the current 651 // default appearance, then update the navigation button now. Otherwise just toggle the activated state. 652 if (!WI.cssManager.forcedAppearance && this._lastKnownDefaultAppearance !== WI.cssManager.defaultAppearance) 653 this._defaultAppearanceDidChange(); 654 else 655 this._forceAppearanceButtonNavigationItem.activated = !!WI.cssManager.forcedAppearance; 656 } 657 585 658 _showRulersChanged() 586 659 {
Note: See TracChangeset
for help on using the changeset viewer.