Changeset 163073 in webkit
- Timestamp:
- Jan 29, 2014, 11:42:07 PM (11 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 2 deleted
- 23 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r163072 r163073 1 2014-01-29 Commit Queue <commit-queue@webkit.org> 2 3 Unreviewed, rolling out r163048. 4 http://trac.webkit.org/changeset/163048 5 https://bugs.webkit.org/show_bug.cgi?id=127890 6 7 Caused many crashes, detected by EWS prior to landing 8 (Requested by ap on #webkit). 9 10 * Modules/mediacontrols/MediaControlsHost.cpp: 11 (WebCore::MediaControlsHost::sortedTrackListForMenu): 12 (WebCore::MediaControlsHost::displayNameForTrack): 13 (WebCore::MediaControlsHost::captionDisplayMode): 14 * WebCore.exp.in: 15 * WebCore.vcxproj/WebCore.vcxproj: 16 * WebCore.vcxproj/WebCore.vcxproj.filters: 17 * WebCore.xcodeproj/project.pbxproj: 18 * css/DocumentRuleSets.cpp: 19 (WebCore::DocumentRuleSets::initUserStyle): 20 * css/InspectorCSSOMWrappers.cpp: 21 (WebCore::InspectorCSSOMWrappers::collectFromDocumentStyleSheetCollection): 22 * dom/Document.cpp: 23 (WebCore::Document::setCompatibilityMode): 24 (WebCore::Document::registerForCaptionPreferencesChangedCallbacks): 25 (WebCore::Document::captionPreferencesChanged): 26 * dom/DocumentStyleSheetCollection.cpp: 27 * dom/DocumentStyleSheetCollection.h: 28 * html/HTMLMediaElement.cpp: 29 (WebCore::HTMLMediaElement::HTMLMediaElement): 30 (WebCore::HTMLMediaElement::parseAttribute): 31 * html/shadow/MediaControlElements.cpp: 32 (WebCore::MediaControlClosedCaptionsTrackListElement::updateDisplay): 33 (WebCore::MediaControlClosedCaptionsTrackListElement::rebuildTrackListMenu): 34 (WebCore::MediaControlTextTrackContainerElement::updateTimerFired): 35 * page/CaptionStyleSheetMediaAF.cpp: Removed. 36 * page/CaptionStyleSheetMediaAF.h: Removed. 37 * page/CaptionUserPreferences.cpp: 38 (WebCore::CaptionUserPreferences::CaptionUserPreferences): 39 (WebCore::CaptionUserPreferences::notify): 40 (WebCore::CaptionUserPreferences::setCaptionDisplayMode): 41 (WebCore::CaptionUserPreferences::userPrefersCaptions): 42 (WebCore::CaptionUserPreferences::setUserPrefersCaptions): 43 (WebCore::CaptionUserPreferences::userPrefersSubtitles): 44 (WebCore::CaptionUserPreferences::setUserPrefersSubtitles): 45 (WebCore::CaptionUserPreferences::userPrefersTextDescriptions): 46 (WebCore::CaptionUserPreferences::setUserPrefersTextDescriptions): 47 (WebCore::CaptionUserPreferences::captionPreferencesChanged): 48 (WebCore::CaptionUserPreferences::textTrackSelectionScore): 49 (WebCore::CaptionUserPreferences::setCaptionsStyleSheetOverride): 50 (WebCore::CaptionUserPreferences::updateCaptionStyleSheetOveride): 51 * page/CaptionUserPreferences.h: 52 (WebCore::CaptionUserPreferences::captionsStyleSheetOverride): 53 (WebCore::CaptionUserPreferences::setInterestedInCaptionPreferenceChanges): 54 (WebCore::CaptionUserPreferences::testingMode): 55 (WebCore::CaptionUserPreferences::setTestingMode): 56 (WebCore::CaptionUserPreferences::pageGroup): 57 * page/CaptionUserPreferencesMediaAF.cpp: 58 (WebCore::userCaptionPreferencesChangedNotificationCallback): 59 (WebCore::CaptionUserPreferencesMediaAF::CaptionUserPreferencesMediaAF): 60 (WebCore::CaptionUserPreferencesMediaAF::userPrefersCaptions): 61 (WebCore::CaptionUserPreferencesMediaAF::userPrefersSubtitles): 62 (WebCore::CaptionUserPreferencesMediaAF::setInterestedInCaptionPreferenceChanges): 63 (WebCore::CaptionUserPreferencesMediaAF::captionPreferencesChanged): 64 (WebCore::CaptionUserPreferencesMediaAF::captionsWindowCSS): 65 (WebCore::CaptionUserPreferencesMediaAF::captionsBackgroundCSS): 66 (WebCore::CaptionUserPreferencesMediaAF::captionsTextColor): 67 (WebCore::CaptionUserPreferencesMediaAF::captionsTextColorCSS): 68 (WebCore::CaptionUserPreferencesMediaAF::windowRoundedCornerRadiusCSS): 69 (WebCore::CaptionUserPreferencesMediaAF::captionsEdgeColorForTextColor): 70 (WebCore::CaptionUserPreferencesMediaAF::cssPropertyWithTextEdgeColor): 71 (WebCore::CaptionUserPreferencesMediaAF::colorPropertyCSS): 72 (WebCore::CaptionUserPreferencesMediaAF::captionsTextEdgeCSS): 73 (WebCore::CaptionUserPreferencesMediaAF::captionsDefaultFontCSS): 74 (WebCore::CaptionUserPreferencesMediaAF::captionsStyleSheetOverride): 75 (WebCore::CaptionUserPreferencesMediaAF::textTrackSelectionScore): 76 (WebCore::CaptionUserPreferencesMediaAF::sortedTrackListForMenu): 77 * page/CaptionUserPreferencesMediaAF.h: 78 * page/Page.cpp: 79 * page/Page.h: 80 * page/PageGroup.cpp: 81 (WebCore::PageGroup::captionPreferencesChanged): 82 (WebCore::PageGroup::captionPreferences): 83 * page/PageGroup.h: 84 * testing/InternalSettings.cpp: 85 (WebCore::InternalSettings::setShouldDisplayTrackKind): 86 (WebCore::InternalSettings::shouldDisplayTrackKind): 87 * testing/Internals.cpp: 88 (WebCore::Internals::resetToConsistentState): 89 (WebCore::Internals::Internals): 90 (WebCore::Internals::captionsStyleSheetOverride): 91 (WebCore::Internals::setCaptionsStyleSheetOverride): 92 (WebCore::Internals::setPrimaryAudioTrackLanguageOverride): 93 (WebCore::Internals::setCaptionDisplayMode): 94 1 95 2014-01-29 Csaba Osztrogonác <ossy@webkit.org> 2 96 -
trunk/Source/WebCore/Modules/mediacontrols/MediaControlsHost.cpp
r163048 r163073 83 83 return Vector<RefPtr<TextTrack>>(); 84 84 85 return page->captionPreferences().sortedTrackListForMenu(trackList); 85 CaptionUserPreferences* captionPreferences = page->group().captionPreferences(); 86 return captionPreferences->sortedTrackListForMenu(trackList); 86 87 } 87 88 … … 95 96 return emptyString(); 96 97 97 return page->captionPreferences().displayNameForTrack(track); 98 CaptionUserPreferences* captionPreferences = page->group().captionPreferences(); 99 return captionPreferences->displayNameForTrack(track); 98 100 } 99 101 … … 114 116 return emptyAtom; 115 117 116 switch (page-> captionPreferences().captionDisplayMode()) {118 switch (page->group().captionPreferences()->captionDisplayMode()) { 117 119 case CaptionUserPreferences::Automatic: 118 120 return automaticKeyword(); -
trunk/Source/WebCore/WebCore.exp.in
r163048 r163073 3064 3064 3065 3065 #if ENABLE(VIDEO_TRACK) 3066 __ZN7WebCore22CaptionUserPreferences29setCaptionsStyleSheetOverrideERKN3WTF6StringE 3067 __ZN7WebCore4Page18captionPreferencesEv 3068 __ZNK7WebCore22CaptionUserPreferences26captionsStyleSheetOverrideEv 3066 __ZN7WebCore9PageGroup18captionPreferencesEv 3069 3067 #endif 3070 3068 -
trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj
r163048 r163073 6985 6985 <ClCompile Include="..\page\AutoscrollController.cpp" /> 6986 6986 <ClCompile Include="..\page\BarProp.cpp" /> 6987 <ClCompile Include="..\page\CaptionStyleSheetMediaAF.cpp">6988 <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release_WinCairo|Win32'">true</ExcludedFromBuild>6989 <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release_WinCairo|x64'">true</ExcludedFromBuild>6990 <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug_WinCairo|Win32'">true</ExcludedFromBuild>6991 <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug_WinCairo|x64'">true</ExcludedFromBuild>6992 </ClCompile>6993 6987 <ClCompile Include="..\page\CaptionUserPreferences.cpp" /> 6994 6988 <ClCompile Include="..\page\CaptionUserPreferencesMediaAF.cpp"> … … 18766 18760 <ClInclude Include="..\page\AutoscrollController.h" /> 18767 18761 <ClInclude Include="..\page\BarProp.h" /> 18768 <ClInclude Include="..\page\CaptionStyleSheetMediaAF.h" />18769 18762 <ClInclude Include="..\page\CaptionUserPreferences.h" /> 18770 18763 <ClInclude Include="..\page\CaptionUserPreferencesMediaAF.h" /> -
trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters
r163048 r163073 6725 6725 <Filter>platform\graphics\opengl</Filter> 6726 6726 </ClCompile> 6727 <ClCompile Include="..\page\CaptionStyleSheetMediaAF.cpp">6728 <Filter>page</Filter>6729 </ClCompile>6730 6727 <ClCompile Include="..\page\CaptionUserPreferencesMediaAF.cpp"> 6731 6728 <Filter>page</Filter> … … 14503 14500 <ClInclude Include="..\platform\graphics\opengl\GLPlatformSurface.h"> 14504 14501 <Filter>platform\graphics\opengl</Filter> 14505 </ClInclude>14506 <ClInclude Include="..\page\CaptionStyleSheetMediaAF.h">14507 <Filter>page</Filter>14508 14502 </ClInclude> 14509 14503 <ClInclude Include="..\page\CaptionUserPreferences.h"> -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r163048 r163073 2294 2294 7CE6CBFB187F370700D46BF5 /* FormatConverter.h in Headers */ = {isa = PBXBuildFile; fileRef = 7CE6CBFA187F370700D46BF5 /* FormatConverter.h */; }; 2295 2295 7CE6CBFD187F394900D46BF5 /* FormatConverter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CE6CBFC187F394900D46BF5 /* FormatConverter.cpp */; }; 2296 7CFC30591895EFAD00E8F43F /* CaptionStyleSheetMediaAF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CFC30571895EFAD00E8F43F /* CaptionStyleSheetMediaAF.cpp */; };2297 7CFC305A1895EFAD00E8F43F /* CaptionStyleSheetMediaAF.h in Headers */ = {isa = PBXBuildFile; fileRef = 7CFC30581895EFAD00E8F43F /* CaptionStyleSheetMediaAF.h */; };2298 2296 7D741BDA177226AA00859170 /* CSSValueKeywords.h in Copy Generated Headers */ = {isa = PBXBuildFile; fileRef = 6565814809D13043000E61D7 /* CSSValueKeywords.h */; }; 2299 2297 7E33CD01127F340D00BE8F17 /* PurgePriority.h in Headers */ = {isa = PBXBuildFile; fileRef = 7E33CD00127F340D00BE8F17 /* PurgePriority.h */; settings = {ATTRIBUTES = (Private, ); }; }; … … 9237 9235 7CE6CBFA187F370700D46BF5 /* FormatConverter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FormatConverter.h; sourceTree = "<group>"; }; 9238 9236 7CE6CBFC187F394900D46BF5 /* FormatConverter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FormatConverter.cpp; sourceTree = "<group>"; }; 9239 7CFC30571895EFAD00E8F43F /* CaptionStyleSheetMediaAF.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CaptionStyleSheetMediaAF.cpp; sourceTree = "<group>"; };9240 7CFC30581895EFAD00E8F43F /* CaptionStyleSheetMediaAF.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CaptionStyleSheetMediaAF.h; sourceTree = "<group>"; };9241 9237 7E33CD00127F340D00BE8F17 /* PurgePriority.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PurgePriority.h; sourceTree = "<group>"; }; 9242 9238 7E37EF2D1339208800B29250 /* SubresourceLoaderCF.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SubresourceLoaderCF.cpp; path = cf/SubresourceLoaderCF.cpp; sourceTree = "<group>"; }; … … 16037 16033 079D086A162F21F900DB8658 /* CaptionUserPreferencesMediaAF.cpp */, 16038 16034 079D0869162F21F900DB8658 /* CaptionUserPreferencesMediaAF.h */, 16039 7CFC30571895EFAD00E8F43F /* CaptionStyleSheetMediaAF.cpp */,16040 7CFC30581895EFAD00E8F43F /* CaptionStyleSheetMediaAF.h */,16041 16035 14D8238A0AF92DF60004F057 /* Chrome.cpp */, 16042 16036 14D823500AF92A790004F057 /* Chrome.h */, … … 22606 22600 9A528E8417D7F52F00AA9518 /* FloatingObjects.h in Headers */, 22607 22601 FE4AADEE16D2C37400026FFC /* AbstractSQLStatement.h in Headers */, 22608 7CFC305A1895EFAD00E8F43F /* CaptionStyleSheetMediaAF.h in Headers */,22609 22602 6E84E9E117668BF100815B68 /* RasterShape.h in Headers */, 22610 22603 FE4AADEF16D2C37400026FFC /* AbstractSQLStatementBackend.h in Headers */, … … 27126 27119 A8EA79FC0A1916DF00A8EF5F /* HTMLLIElement.cpp in Sources */, 27127 27120 A871DC210A15205700B12A68 /* HTMLLinkElement.cpp in Sources */, 27128 7CFC30591895EFAD00E8F43F /* CaptionStyleSheetMediaAF.cpp in Sources */,27129 27121 A8EA7D320A19385500A8EF5F /* HTMLMapElement.cpp in Sources */, 27130 27122 A8EA7CAC0A192B9C00A8EF5F /* HTMLMarqueeElement.cpp in Sources */, -
trunk/Source/WebCore/css/DocumentRuleSets.cpp
r163048 r163073 52 52 if (CSSStyleSheet* pageUserSheet = styleSheetCollection.pageUserSheet()) 53 53 tempUserStyle->addRulesFromSheet(&pageUserSheet->contents(), medium, &resolver); 54 if (CSSStyleSheet* captionsStyleSheet = styleSheetCollection.captionsStyleSheet())55 tempUserStyle->addRulesFromSheet(&captionsStyleSheet->contents(), medium, &resolver);56 54 collectRulesFromUserStyleSheets(styleSheetCollection.injectedUserStyleSheets(), *tempUserStyle, medium, resolver); 57 55 collectRulesFromUserStyleSheets(styleSheetCollection.documentUserStyleSheets(), *tempUserStyle, medium, resolver); -
trunk/Source/WebCore/css/InspectorCSSOMWrappers.cpp
r163048 r163073 108 108 collectFromStyleSheets(styleSheetCollection.activeAuthorStyleSheets()); 109 109 collect(styleSheetCollection.pageUserSheet()); 110 collect(styleSheetCollection.captionsStyleSheet());111 110 collectFromStyleSheets(styleSheetCollection.injectedUserStyleSheets()); 112 111 collectFromStyleSheets(styleSheetCollection.documentUserStyleSheets()); -
trunk/Source/WebCore/dom/Document.cpp
r163048 r163073 749 749 // All user stylesheets have to reparse using the different mode. 750 750 m_styleSheetCollection.clearPageUserSheet(); 751 m_styleSheetCollection.invalidateCaptionsStyleSheet();752 751 m_styleSheetCollection.invalidateInjectedStyleSheetCache(); 753 752 } … … 4173 4172 void Document::registerForCaptionPreferencesChangedCallbacks(Element* e) 4174 4173 { 4174 if (page()) 4175 page()->group().captionPreferences()->setInterestedInCaptionPreferenceChanges(); 4176 4175 4177 m_captionPreferencesChangedElements.add(e); 4176 4178 } … … 4183 4185 void Document::captionPreferencesChanged() 4184 4186 { 4185 m_styleSheetCollection.invalidateCaptionsStyleSheet(); 4186 styleResolverChanged(DeferRecalcStyle); 4187 4188 for (auto* element : m_captionPreferencesChangedElements) 4189 element->captionPreferencesChanged(); 4187 HashSet<Element*>::iterator end = m_captionPreferencesChangedElements.end(); 4188 for (HashSet<Element*>::iterator it = m_captionPreferencesChangedElements.begin(); it != end; ++it) 4189 (*it)->captionPreferencesChanged(); 4190 4190 } 4191 4191 #endif -
trunk/Source/WebCore/dom/DocumentStyleSheetCollection.cpp
r163048 r163073 30 30 31 31 #include "CSSStyleSheet.h" 32 #include "CaptionUserPreferences.h"33 32 #include "Element.h" 34 33 #include "HTMLIFrameElement.h" … … 118 117 if (pageUserSheet()) 119 118 m_document.styleResolverChanged(RecalcStyleImmediately); 120 }121 122 CSSStyleSheet* DocumentStyleSheetCollection::captionsStyleSheet()123 {124 updateCaptionsStyleSheet();125 return m_captionsStyleSheet.get();126 }127 128 void DocumentStyleSheetCollection::updateCaptionsStyleSheet()129 {130 // Identify our override style sheet with a unique URL - a new scheme and a UUID.131 DEFINE_STATIC_LOCAL(URL, captionsStyleSheetURL, (ParsedURLString, "user-captions-override:01F6AF12-C3B0-4F70-AF5E-A3E00234DC23"));132 133 if (m_captionsStyleSheet)134 return;135 136 Page* owningPage = m_document.page();137 if (!owningPage)138 return;139 140 String captionsStyleSheetText = owningPage->captionPreferences().captionsStyleSheet();141 if (captionsStyleSheetText.isEmpty())142 return;143 144 // Parse the sheet and cache it.145 m_captionsStyleSheet = CSSStyleSheet::createInline(m_document, captionsStyleSheetURL);146 m_captionsStyleSheet->contents().parseString(captionsStyleSheetText);147 }148 149 void DocumentStyleSheetCollection::invalidateCaptionsStyleSheet()150 {151 if (m_captionsStyleSheet) {152 m_captionsStyleSheet = nullptr;153 m_document.styleResolverChanged(DeferRecalcStyle);154 }155 119 } 156 120 -
trunk/Source/WebCore/dom/DocumentStyleSheetCollection.h
r163048 r163073 54 54 55 55 CSSStyleSheet* pageUserSheet(); 56 CSSStyleSheet* captionsStyleSheet();57 56 const Vector<RefPtr<CSSStyleSheet>>& documentUserStyleSheets() const { return m_userStyleSheets; } 58 57 const Vector<RefPtr<CSSStyleSheet>>& documentAuthorStyleSheets() const { return m_authorStyleSheets; } … … 65 64 void clearPageUserSheet(); 66 65 void updatePageUserSheet(); 67 68 void invalidateCaptionsStyleSheet();69 void updateCaptionsStyleSheet();70 71 66 void invalidateInjectedStyleSheetCache(); 72 67 void updateInjectedStyleSheetCache() const; … … 147 142 148 143 RefPtr<CSSStyleSheet> m_pageUserSheet; 149 RefPtr<CSSStyleSheet> m_captionsStyleSheet;150 144 151 145 mutable Vector<RefPtr<CSSStyleSheet>> m_injectedUserStyleSheets; -
trunk/Source/WebCore/html/HTMLMediaElement.cpp
r163048 r163073 380 380 document.registerForCaptionPreferencesChangedCallbacks(this); 381 381 if (document.page()) 382 m_captionDisplayMode = document.page()-> captionPreferences().captionDisplayMode();382 m_captionDisplayMode = document.page()->group().captionPreferences()->captionDisplayMode(); 383 383 #endif 384 384 } … … 3425 3425 3426 3426 Page* page = document().page(); 3427 CaptionUserPreferences* captionPreferences = page ? &page->captionPreferences() : nullptr;3427 CaptionUserPreferences* captionPreferences = page? page->group().captionPreferences() : 0; 3428 3428 CaptionUserPreferences::CaptionDisplayMode displayMode = captionPreferences ? captionPreferences->captionDisplayMode() : CaptionUserPreferences::Automatic; 3429 3429 … … 3535 3535 } 3536 3536 3537 if (!document().page()) 3538 return; 3539 3540 CaptionUserPreferences::CaptionDisplayMode displayMode = document().page()->captionPreferences().captionDisplayMode(); 3537 CaptionUserPreferences* captionPreferences = document().page() ? document().page()->group().captionPreferences() : 0; 3538 if (!captionPreferences) 3539 return; 3540 3541 CaptionUserPreferences::CaptionDisplayMode displayMode = captionPreferences->captionDisplayMode(); 3541 3542 if (trackToSelect == TextTrack::captionMenuOffItem()) 3542 3543 displayMode = CaptionUserPreferences::ForcedOnly; … … 3546 3547 displayMode = CaptionUserPreferences::AlwaysOn; 3547 3548 if (trackToSelect->language().length()) 3548 document().page()->captionPreferences().setPreferredLanguage(trackToSelect->language());3549 captionPreferences->setPreferredLanguage(trackToSelect->language()); 3549 3550 3550 3551 // Set m_captionDisplayMode here so we don't reconfigure again when the preference changed notification comes through. … … 3552 3553 } 3553 3554 3554 document().page()->captionPreferences().setCaptionDisplayMode(displayMode);3555 captionPreferences->setCaptionDisplayMode(displayMode); 3555 3556 } 3556 3557 … … 5256 5257 if (!document().page()) 5257 5258 return; 5258 5259 CaptionUserPreferences::CaptionDisplayMode displayMode = document().page()-> captionPreferences().captionDisplayMode();5259 5260 CaptionUserPreferences::CaptionDisplayMode displayMode = document().page()->group().captionPreferences()->captionDisplayMode(); 5260 5261 if (m_captionDisplayMode == displayMode) 5261 5262 return; -
trunk/Source/WebCore/html/shadow/MediaControlElements.cpp
r163048 r163073 821 821 if (!document().page()) 822 822 return; 823 CaptionUserPreferences::CaptionDisplayMode displayMode = document().page()-> captionPreferences().captionDisplayMode();823 CaptionUserPreferences::CaptionDisplayMode displayMode = document().page()->group().captionPreferences()->captionDisplayMode(); 824 824 825 825 HTMLMediaElement* mediaElement = parentMediaElement(this); … … 897 897 if (!document().page()) 898 898 return; 899 900 CaptionUserPreferences& captionPreferences = document().page()->captionPreferences(); 901 Vector<RefPtr<TextTrack>> tracksForMenu = captionPreferences.sortedTrackListForMenu(trackList); 899 CaptionUserPreferences* captionPreferences = document().page()->group().captionPreferences(); 900 Vector<RefPtr<TextTrack>> tracksForMenu = captionPreferences->sortedTrackListForMenu(trackList); 902 901 903 902 RefPtr<Element> captionsHeader = document().createElement(h3Tag, ASSERT_NO_EXCEPTION); … … 909 908 RefPtr<TextTrack> textTrack = tracksForMenu[i]; 910 909 RefPtr<Element> menuItem = document().createElement(liTag, ASSERT_NO_EXCEPTION); 911 menuItem->appendChild(document().createTextNode(captionPreferences .displayNameForTrack(textTrack.get())));910 menuItem->appendChild(document().createTextNode(captionPreferences->displayNameForTrack(textTrack.get()))); 912 911 captionsMenuList->appendChild(menuItem); 913 912 m_menuItems.append(menuItem); … … 1333 1332 1334 1333 float smallestDimension = std::min(m_videoDisplaySize.size().height(), m_videoDisplaySize.size().width()); 1335 float fontScale = document().page()-> captionPreferences().captionFontSizeScaleAndImportance(m_fontSizeIsImportant);1334 float fontScale = document().page()->group().captionPreferences()->captionFontSizeScaleAndImportance(m_fontSizeIsImportant); 1336 1335 m_fontSize = lroundf(smallestDimension * fontScale); 1337 1336 -
trunk/Source/WebCore/page/CaptionUserPreferences.cpp
r163048 r163073 29 29 30 30 #include "CaptionUserPreferences.h" 31 32 #include "HTMLMediaElement.h" 31 #include "DOMWrapperWorld.h" 33 32 #include "Page.h" 34 #include "Page Cache.h"33 #include "PageGroup.h" 35 34 #include "Settings.h" 36 35 #include "TextTrackList.h" 36 #include "UserStyleSheetTypes.h" 37 37 38 38 namespace WebCore { 39 39 40 CaptionUserPreferences::CaptionUserPreferences( )41 : m_ timer(this, &CaptionUserPreferences::timerFired)40 CaptionUserPreferences::CaptionUserPreferences(PageGroup& group) 41 : m_pageGroup(group) 42 42 , m_displayMode(ForcedOnly) 43 , m_timer(this, &CaptionUserPreferences::timerFired) 43 44 , m_testingMode(false) 45 , m_havePreferences(false) 44 46 { 45 47 } … … 56 58 void CaptionUserPreferences::notify() 57 59 { 60 m_havePreferences = true; 58 61 if (!m_timer.isActive()) 59 62 m_timer.startOneShot(0); … … 68 71 { 69 72 m_displayMode = mode; 70 notify(); 71 } 72 73 bool CaptionUserPreferences::userPrefersCaptions(Document& document) const 74 { 75 Settings* settings = document.settings(); 76 if (!settings) 73 if (m_testingMode && mode != AlwaysOn) { 74 setUserPrefersCaptions(false); 75 setUserPrefersSubtitles(false); 76 } 77 notify(); 78 } 79 80 bool CaptionUserPreferences::userPrefersCaptions() const 81 { 82 Page* page = *(m_pageGroup.pages().begin()); 83 if (!page) 77 84 return false; 78 85 79 return settings->shouldDisplayCaptions(); 80 } 81 82 bool CaptionUserPreferences::userPrefersSubtitles(Document& document) const 83 { 84 Settings* settings = document.settings(); 85 if (!settings) 86 return page->settings().shouldDisplayCaptions(); 87 } 88 89 void CaptionUserPreferences::setUserPrefersCaptions(bool preference) 90 { 91 Page* page = *(m_pageGroup.pages().begin()); 92 if (!page) 93 return; 94 95 page->settings().setShouldDisplayCaptions(preference); 96 notify(); 97 } 98 99 bool CaptionUserPreferences::userPrefersSubtitles() const 100 { 101 Page* page = *(pageGroup().pages().begin()); 102 if (!page) 86 103 return false; 87 104 88 return settings->shouldDisplaySubtitles(); 89 } 90 91 bool CaptionUserPreferences::userPrefersTextDescriptions(Document& document) const 92 { 93 Settings* settings = document.settings(); 94 if (!settings) 105 return page->settings().shouldDisplaySubtitles(); 106 } 107 108 void CaptionUserPreferences::setUserPrefersSubtitles(bool preference) 109 { 110 Page* page = *(m_pageGroup.pages().begin()); 111 if (!page) 112 return; 113 114 page->settings().setShouldDisplaySubtitles(preference); 115 notify(); 116 } 117 118 bool CaptionUserPreferences::userPrefersTextDescriptions() const 119 { 120 Page* page = *(m_pageGroup.pages().begin()); 121 if (!page) 95 122 return false; 96 97 return settings->shouldDisplayTextDescriptions(); 123 124 return page->settings().shouldDisplayTextDescriptions(); 125 } 126 127 void CaptionUserPreferences::setUserPrefersTextDescriptions(bool preference) 128 { 129 Page* page = *(m_pageGroup.pages().begin()); 130 if (!page) 131 return; 132 133 page->settings().setShouldDisplayTextDescriptions(preference); 134 notify(); 135 } 136 137 void CaptionUserPreferences::captionPreferencesChanged() 138 { 139 m_pageGroup.captionPreferencesChanged(); 98 140 } 99 141 … … 155 197 } 156 198 157 int CaptionUserPreferences::textTrackSelectionScore(TextTrack* track, HTMLMediaElement* element) const199 int CaptionUserPreferences::textTrackSelectionScore(TextTrack* track, HTMLMediaElement*) const 158 200 { 159 201 int trackScore = 0; … … 162 204 return trackScore; 163 205 164 if (!userPrefersSubtitles( element->document()) && !userPrefersCaptions(element->document()))206 if (!userPrefersSubtitles() && !userPrefersCaptions()) 165 207 return trackScore; 166 208 167 if (track->kind() == TextTrack::subtitlesKeyword() && userPrefersSubtitles( element->document()))209 if (track->kind() == TextTrack::subtitlesKeyword() && userPrefersSubtitles()) 168 210 trackScore = 1; 169 else if (track->kind() == TextTrack::captionsKeyword() && userPrefersCaptions( element->document()))211 else if (track->kind() == TextTrack::captionsKeyword() && userPrefersCaptions()) 170 212 trackScore = 1; 171 213 … … 187 229 } 188 230 189 String CaptionUserPreferences::captionsStyleSheet()190 {191 if (!m_captionsStyleSheetOverride.isEmpty() || testingMode())192 return m_captionsStyleSheetOverride;193 194 return platformCaptionsStyleSheet();195 }196 197 231 void CaptionUserPreferences::setCaptionsStyleSheetOverride(const String& override) 198 232 { 199 233 m_captionsStyleSheetOverride = override; 200 captionPreferencesChanged(); 201 } 202 203 String CaptionUserPreferences::captionsStyleSheetOverride() const 204 { 205 return m_captionsStyleSheetOverride; 234 updateCaptionStyleSheetOveride(); 235 } 236 237 void CaptionUserPreferences::updateCaptionStyleSheetOveride() 238 { 239 // Identify our override style sheet with a unique URL - a new scheme and a UUID. 240 DEFINE_STATIC_LOCAL(URL, captionsStyleSheetURL, (ParsedURLString, "user-captions-override:01F6AF12-C3B0-4F70-AF5E-A3E00234DC23")); 241 242 m_pageGroup.removeUserStyleSheetFromWorld(mainThreadNormalWorld(), captionsStyleSheetURL); 243 244 String captionsOverrideStyleSheet = captionsStyleSheetOverride(); 245 if (captionsOverrideStyleSheet.isEmpty()) 246 return; 247 248 m_pageGroup.addUserStyleSheetToWorld(mainThreadNormalWorld(), captionsOverrideStyleSheet, captionsStyleSheetURL, Vector<String>(), 249 Vector<String>(), InjectInAllFrames, UserStyleAuthorLevel, InjectInExistingDocuments); 206 250 } 207 251 … … 212 256 return defaultLanguage(); 213 257 } 214 215 void CaptionUserPreferences::captionPreferencesChanged() 216 { 217 Page::updateStyleForAllPagesForCaptionPreferencesChanged(); 218 pageCache()->markPagesForCaptionPreferencesChanged(); 219 } 220 221 } // namespace WebCore 258 259 } 222 260 223 261 #endif // ENABLE(VIDEO_TRACK) -
trunk/Source/WebCore/page/CaptionUserPreferences.h
r163048 r163073 44 44 class CaptionUserPreferences { 45 45 public: 46 CaptionUserPreferences( );46 CaptionUserPreferences(PageGroup&); 47 47 virtual ~CaptionUserPreferences(); 48 49 String captionsStyleSheet();50 48 51 49 enum CaptionDisplayMode { … … 54 52 AlwaysOn 55 53 }; 56 57 54 virtual CaptionDisplayMode captionDisplayMode() const; 58 55 virtual void setCaptionDisplayMode(CaptionDisplayMode); … … 60 57 virtual int textTrackSelectionScore(TextTrack*, HTMLMediaElement*) const; 61 58 virtual int textTrackLanguageSelectionScore(TextTrack*, const Vector<String>&) const; 62 virtual bool userPrefersCaptions(Document&) const; 63 virtual bool userPrefersSubtitles(Document&) const; 64 virtual bool userPrefersTextDescriptions(Document&) const; 59 60 virtual bool userPrefersCaptions() const; 61 virtual void setUserPrefersCaptions(bool); 62 63 virtual bool userPrefersSubtitles() const; 64 virtual void setUserPrefersSubtitles(bool preference); 65 66 virtual bool userPrefersTextDescriptions() const; 67 virtual void setUserPrefersTextDescriptions(bool preference); 65 68 66 69 virtual float captionFontSizeScaleAndImportance(bool& important) const { important = false; return 0.05f; } 70 71 virtual String captionsStyleSheetOverride() const { return m_captionsStyleSheetOverride; } 72 virtual void setCaptionsStyleSheetOverride(const String&); 73 74 virtual void setInterestedInCaptionPreferenceChanges() { } 75 76 virtual void captionPreferencesChanged(); 67 77 68 78 virtual void setPreferredLanguage(const String&); … … 72 82 virtual Vector<RefPtr<TextTrack>> sortedTrackListForMenu(TextTrackList*); 73 83 74 void captionPreferencesChanged();75 76 // These are used for testing mode only.77 void setCaptionsStyleSheetOverride(const String&);78 String captionsStyleSheetOverride() const;79 84 void setPrimaryAudioTrackLanguageOverride(const String& language) { m_primaryAudioTrackLanguageOverride = language; } 80 85 String primaryAudioTrackLanguageOverride() const; 81 void setTestingMode(bool override) { m_testingMode = override; } 82 bool testingMode() const { return m_testingMode; } 86 87 virtual bool testingMode() const { return m_testingMode; } 88 virtual void setTestingMode(bool override) { m_testingMode = override; } 83 89 90 PageGroup& pageGroup() const { return m_pageGroup; } 91 92 protected: 93 void updateCaptionStyleSheetOveride(); 94 84 95 private: 85 96 void timerFired(Timer<CaptionUserPreferences>&); 86 97 void notify(); 87 98 88 virtual String platformCaptionsStyleSheet() { return String(); }89 99 PageGroup& m_pageGroup; 100 CaptionDisplayMode m_displayMode; 90 101 Timer<CaptionUserPreferences> m_timer; 91 92 // These are used for testing mode only.93 CaptionDisplayMode m_displayMode;94 102 String m_userPreferredLanguage; 95 103 String m_captionsStyleSheetOverride; 96 104 String m_primaryAudioTrackLanguageOverride; 97 105 bool m_testingMode; 106 bool m_havePreferences; 98 107 }; 99 108 100 109 } 101 110 #endif -
trunk/Source/WebCore/page/CaptionUserPreferencesMediaAF.cpp
r163048 r163073 30 30 #include "CaptionUserPreferencesMediaAF.h" 31 31 32 #include "CaptionStyleSheetMediaAF.h" 32 #if HAVE(MEDIA_ACCESSIBILITY_FRAMEWORK) 33 #include "CoreText/CoreText.h" 34 #endif 33 35 #include "FloatConversion.h" 34 36 #include "HTMLMediaElement.h" … … 41 43 #include "TextTrackCue.h" 42 44 #include "TextTrackList.h" 45 #include "UserStyleSheetTypes.h" 43 46 #include <wtf/RetainPtr.h> 44 47 #include <wtf/text/CString.h> … … 74 77 75 78 SOFT_LINK_AVF_FRAMEWORK(MediaAccessibility) 79 SOFT_LINK_AVF_FRAMEWORK(CoreText) 76 80 77 81 SOFT_LINK_AVF_FRAMEWORK_IMPORT(MediaAccessibility, MACaptionAppearanceGetDisplayType, MACaptionAppearanceDisplayType, (MACaptionAppearanceDomain domain), (domain)) 78 82 SOFT_LINK_AVF_FRAMEWORK_IMPORT(MediaAccessibility, MACaptionAppearanceSetDisplayType, void, (MACaptionAppearanceDomain domain, MACaptionAppearanceDisplayType displayType), (domain, displayType)) 83 SOFT_LINK_AVF_FRAMEWORK_IMPORT(MediaAccessibility, MACaptionAppearanceCopyForegroundColor, CGColorRef, (MACaptionAppearanceDomain domain, MACaptionAppearanceBehavior *behavior), (domain, behavior)) 84 SOFT_LINK_AVF_FRAMEWORK_IMPORT(MediaAccessibility, MACaptionAppearanceCopyBackgroundColor, CGColorRef, (MACaptionAppearanceDomain domain, MACaptionAppearanceBehavior *behavior), (domain, behavior)) 85 SOFT_LINK_AVF_FRAMEWORK_IMPORT(MediaAccessibility, MACaptionAppearanceCopyWindowColor, CGColorRef, (MACaptionAppearanceDomain domain, MACaptionAppearanceBehavior *behavior), (domain, behavior)) 86 SOFT_LINK_AVF_FRAMEWORK_IMPORT(MediaAccessibility, MACaptionAppearanceGetForegroundOpacity, CGFloat, (MACaptionAppearanceDomain domain, MACaptionAppearanceBehavior *behavior), (domain, behavior)) 87 SOFT_LINK_AVF_FRAMEWORK_IMPORT(MediaAccessibility, MACaptionAppearanceGetBackgroundOpacity, CGFloat, (MACaptionAppearanceDomain domain, MACaptionAppearanceBehavior *behavior), (domain, behavior)) 88 SOFT_LINK_AVF_FRAMEWORK_IMPORT(MediaAccessibility, MACaptionAppearanceGetWindowOpacity, CGFloat, (MACaptionAppearanceDomain domain, MACaptionAppearanceBehavior *behavior), (domain, behavior)) 89 SOFT_LINK_AVF_FRAMEWORK_IMPORT(MediaAccessibility, MACaptionAppearanceGetWindowRoundedCornerRadius, CGFloat, (MACaptionAppearanceDomain domain, MACaptionAppearanceBehavior *behavior), (domain, behavior)) 90 SOFT_LINK_AVF_FRAMEWORK_IMPORT(MediaAccessibility, MACaptionAppearanceCopyFontDescriptorForStyle, CTFontDescriptorRef, (MACaptionAppearanceDomain domain, MACaptionAppearanceBehavior *behavior, MACaptionAppearanceFontStyle fontStyle), (domain, behavior, fontStyle)) 91 SOFT_LINK_AVF_FRAMEWORK_IMPORT(MediaAccessibility, MACaptionAppearanceGetRelativeCharacterSize, CGFloat, (MACaptionAppearanceDomain domain, MACaptionAppearanceBehavior *behavior), (domain, behavior)) 92 SOFT_LINK_AVF_FRAMEWORK_IMPORT(MediaAccessibility, MACaptionAppearanceGetTextEdgeStyle, MACaptionAppearanceTextEdgeStyle, (MACaptionAppearanceDomain domain, MACaptionAppearanceBehavior *behavior), (domain, behavior)) 79 93 SOFT_LINK_AVF_FRAMEWORK_IMPORT(MediaAccessibility, MACaptionAppearanceAddSelectedLanguage, bool, (MACaptionAppearanceDomain domain, CFStringRef language), (domain, language)); 80 94 SOFT_LINK_AVF_FRAMEWORK_IMPORT(MediaAccessibility, MACaptionAppearanceCopySelectedLanguages, CFArrayRef, (MACaptionAppearanceDomain domain), (domain)); 81 95 SOFT_LINK_AVF_FRAMEWORK_IMPORT(MediaAccessibility, MACaptionAppearanceCopyPreferredCaptioningMediaCharacteristics, CFArrayRef, (MACaptionAppearanceDomain domain), (domain)); 82 SOFT_LINK_AVF_FRAMEWORK_IMPORT(MediaAccessibility, MACaptionAppearanceGetRelativeCharacterSize, CGFloat, (MACaptionAppearanceDomain domain, MACaptionAppearanceBehavior *behavior), (domain, behavior)) 96 97 SOFT_LINK_AVF_FRAMEWORK_IMPORT(CoreText, CTFontDescriptorCopyAttribute, CFTypeRef, (CTFontDescriptorRef descriptor, CFStringRef attribute), (descriptor, attribute)); 83 98 84 99 #if PLATFORM(WIN) … … 86 101 #define MACaptionAppearanceGetDisplayType softLink_MACaptionAppearanceGetDisplayType 87 102 #define MACaptionAppearanceSetDisplayType softLink_MACaptionAppearanceSetDisplayType 103 #define MACaptionAppearanceCopyForegroundColor softLink_MACaptionAppearanceCopyForegroundColor 104 #define MACaptionAppearanceCopyBackgroundColor softLink_MACaptionAppearanceCopyBackgroundColor 105 #define MACaptionAppearanceCopyWindowColor softLink_MACaptionAppearanceCopyWindowColor 106 #define MACaptionAppearanceGetForegroundOpacity softLink_MACaptionAppearanceGetForegroundOpacity 107 #define MACaptionAppearanceGetBackgroundOpacity softLink_MACaptionAppearanceGetBackgroundOpacity 108 #define MACaptionAppearanceGetWindowOpacity softLink_MACaptionAppearanceGetWindowOpacity 109 #define MACaptionAppearanceGetWindowRoundedCornerRadius softLink_MACaptionAppearanceGetWindowRoundedCornerRadius 110 #define MACaptionAppearanceCopyFontDescriptorForStyle softLink_MACaptionAppearanceCopyFontDescriptorForStyle 111 #define MACaptionAppearanceGetRelativeCharacterSize softLink_MACaptionAppearanceGetRelativeCharacterSize 112 #define MACaptionAppearanceGetTextEdgeStyle softLink_MACaptionAppearanceGetTextEdgeStyle 88 113 #define MACaptionAppearanceAddSelectedLanguage softLink_MACaptionAppearanceAddSelectedLanguage 89 114 #define MACaptionAppearanceCopySelectedLanguages softLink_MACaptionAppearanceCopySelectedLanguages 90 115 #define MACaptionAppearanceCopyPreferredCaptioningMediaCharacteristics softLink_MACaptionAppearanceCopyPreferredCaptioningMediaCharacteristics 91 #define MACaptionAppearanceGetRelativeCharacterSize softLink_MACaptionAppearanceGetRelativeCharacterSize116 #define CTFontDescriptorCopyAttribute softLink_CTFontDescriptorCopyAttribute 92 117 #endif 93 118 … … 95 120 #define kMAXCaptionAppearanceSettingsChangedNotification getkMAXCaptionAppearanceSettingsChangedNotification() 96 121 97 #endif 98 122 SOFT_LINK_AVF_POINTER(CoreText, kCTFontNameAttribute, CFStringRef) 123 #define kCTFontNameAttribute getkCTFontNameAttribute() 124 #endif 99 125 100 126 namespace WebCore { … … 104 130 { 105 131 #if !PLATFORM(IOS) 106 static_cast<CaptionUserPreferencesMediaAF*>(observer)->caption ApperenceChanged();132 static_cast<CaptionUserPreferencesMediaAF*>(observer)->captionPreferencesChanged(); 107 133 #else 108 134 WebThreadRun(^{ 109 static_cast<CaptionUserPreferencesMediaAF*>(observer)->caption ApperenceChanged();135 static_cast<CaptionUserPreferencesMediaAF*>(observer)->captionPreferencesChanged(); 110 136 }); 111 137 #endif … … 113 139 #endif 114 140 115 CaptionUserPreferencesMediaAF::CaptionUserPreferencesMediaAF( )116 { 141 CaptionUserPreferencesMediaAF::CaptionUserPreferencesMediaAF(PageGroup& group) 142 : CaptionUserPreferences(group) 117 143 #if HAVE(MEDIA_ACCESSIBILITY_FRAMEWORK) 118 if (MediaAccessibilityLibrary() && kMAXCaptionAppearanceSettingsChangedNotification)119 CFNotificationCenterAddObserver(CFNotificationCenterGetLocalCenter(), this, userCaptionPreferencesChangedNotificationCallback, kMAXCaptionAppearanceSettingsChangedNotification, 0, CFNotificationSuspensionBehaviorCoalesce); 120 #endif 144 , m_listeningForPreferenceChanges(false) 145 #endif 146 { 121 147 } 122 148 … … 130 156 131 157 #if HAVE(MEDIA_ACCESSIBILITY_FRAMEWORK) 132 133 void CaptionUserPreferencesMediaAF::captionApperenceChanged()134 {135 // Invalidate the caption style sheet.136 m_captionStyleSheet = String();137 138 // Tell the base class to invalidate all the uses of it.139 captionPreferencesChanged();140 }141 158 142 159 CaptionUserPreferences::CaptionDisplayMode CaptionUserPreferencesMediaAF::captionDisplayMode() const … … 190 207 } 191 208 192 bool CaptionUserPreferencesMediaAF::userPrefersCaptions( Document& document) const193 { 194 bool captionSetting = CaptionUserPreferences::userPrefersCaptions( document);209 bool CaptionUserPreferencesMediaAF::userPrefersCaptions() const 210 { 211 bool captionSetting = CaptionUserPreferences::userPrefersCaptions(); 195 212 if (captionSetting || testingMode() || !MediaAccessibilityLibrary()) 196 213 return captionSetting; … … 200 217 } 201 218 202 bool CaptionUserPreferencesMediaAF::userPrefersSubtitles( Document& document) const203 { 204 bool subtitlesSetting = CaptionUserPreferences::userPrefersSubtitles( document);219 bool CaptionUserPreferencesMediaAF::userPrefersSubtitles() const 220 { 221 bool subtitlesSetting = CaptionUserPreferences::userPrefersSubtitles(); 205 222 if (subtitlesSetting || testingMode() || !MediaAccessibilityLibrary()) 206 223 return subtitlesSetting; … … 208 225 RetainPtr<CFArrayRef> captioningMediaCharacteristics = adoptCF(MACaptionAppearanceCopyPreferredCaptioningMediaCharacteristics(kMACaptionAppearanceDomainUser)); 209 226 return !(captioningMediaCharacteristics && CFArrayGetCount(captioningMediaCharacteristics.get())); 227 } 228 229 void CaptionUserPreferencesMediaAF::setInterestedInCaptionPreferenceChanges() 230 { 231 if (!MediaAccessibilityLibrary()) 232 return; 233 234 if (!kMAXCaptionAppearanceSettingsChangedNotification) 235 return; 236 237 if (!m_listeningForPreferenceChanges) { 238 m_listeningForPreferenceChanges = true; 239 CFNotificationCenterAddObserver(CFNotificationCenterGetLocalCenter(), this, userCaptionPreferencesChangedNotificationCallback, kMAXCaptionAppearanceSettingsChangedNotification, 0, CFNotificationSuspensionBehaviorCoalesce); 240 updateCaptionStyleSheetOveride(); 241 } 242 } 243 244 void CaptionUserPreferencesMediaAF::captionPreferencesChanged() 245 { 246 if (m_listeningForPreferenceChanges) 247 updateCaptionStyleSheetOveride(); 248 249 CaptionUserPreferences::captionPreferencesChanged(); 250 } 251 252 String CaptionUserPreferencesMediaAF::captionsWindowCSS() const 253 { 254 MACaptionAppearanceBehavior behavior; 255 RetainPtr<CGColorRef> color = adoptCF(MACaptionAppearanceCopyWindowColor(kMACaptionAppearanceDomainUser, &behavior)); 256 257 Color windowColor(color.get()); 258 if (!windowColor.isValid()) 259 windowColor = Color::transparent; 260 261 bool important = behavior == kMACaptionAppearanceBehaviorUseValue; 262 CGFloat opacity = MACaptionAppearanceGetWindowOpacity(kMACaptionAppearanceDomainUser, &behavior); 263 if (!important) 264 important = behavior == kMACaptionAppearanceBehaviorUseValue; 265 String windowStyle = colorPropertyCSS(CSSPropertyBackgroundColor, Color(windowColor.red(), windowColor.green(), windowColor.blue(), static_cast<int>(opacity * 255)), important); 266 267 if (!opacity) 268 return windowStyle; 269 270 StringBuilder builder; 271 builder.append(windowStyle); 272 builder.append(getPropertyNameString(CSSPropertyPadding)); 273 builder.append(": .4em !important;"); 274 275 return builder.toString(); 276 } 277 278 String CaptionUserPreferencesMediaAF::captionsBackgroundCSS() const 279 { 280 // This default value must be the same as the one specified in mediaControls.css for -webkit-media-text-track-past-nodes 281 // and webkit-media-text-track-future-nodes. 282 DEFINE_STATIC_LOCAL(Color, defaultBackgroundColor, (Color(0, 0, 0, 0.8 * 255))); 283 284 MACaptionAppearanceBehavior behavior; 285 286 RetainPtr<CGColorRef> color = adoptCF(MACaptionAppearanceCopyBackgroundColor(kMACaptionAppearanceDomainUser, &behavior)); 287 Color backgroundColor(color.get()); 288 if (!backgroundColor.isValid()) 289 backgroundColor = defaultBackgroundColor; 290 291 bool important = behavior == kMACaptionAppearanceBehaviorUseValue; 292 CGFloat opacity = MACaptionAppearanceGetBackgroundOpacity(kMACaptionAppearanceDomainUser, &behavior); 293 if (!important) 294 important = behavior == kMACaptionAppearanceBehaviorUseValue; 295 return colorPropertyCSS(CSSPropertyBackgroundColor, Color(backgroundColor.red(), backgroundColor.green(), backgroundColor.blue(), static_cast<int>(opacity * 255)), important); 296 } 297 298 Color CaptionUserPreferencesMediaAF::captionsTextColor(bool& important) const 299 { 300 MACaptionAppearanceBehavior behavior; 301 RetainPtr<CGColorRef> color = adoptCF(MACaptionAppearanceCopyForegroundColor(kMACaptionAppearanceDomainUser, &behavior)); 302 Color textColor(color.get()); 303 if (!textColor.isValid()) 304 // This default value must be the same as the one specified in mediaControls.css for -webkit-media-text-track-container. 305 textColor = Color::white; 306 307 important = behavior == kMACaptionAppearanceBehaviorUseValue; 308 CGFloat opacity = MACaptionAppearanceGetForegroundOpacity(kMACaptionAppearanceDomainUser, &behavior); 309 if (!important) 310 important = behavior == kMACaptionAppearanceBehaviorUseValue; 311 return Color(textColor.red(), textColor.green(), textColor.blue(), static_cast<int>(opacity * 255)); 312 } 313 314 String CaptionUserPreferencesMediaAF::captionsTextColorCSS() const 315 { 316 bool important; 317 Color textColor = captionsTextColor(important); 318 319 if (!textColor.isValid()) 320 return emptyString(); 321 322 return colorPropertyCSS(CSSPropertyColor, textColor, important); 323 } 324 325 String CaptionUserPreferencesMediaAF::windowRoundedCornerRadiusCSS() const 326 { 327 MACaptionAppearanceBehavior behavior; 328 CGFloat radius = MACaptionAppearanceGetWindowRoundedCornerRadius(kMACaptionAppearanceDomainUser, &behavior); 329 if (!radius) 330 return emptyString(); 331 332 StringBuilder builder; 333 builder.append(getPropertyNameString(CSSPropertyBorderRadius)); 334 builder.append(String::format(":%.02fpx", radius)); 335 if (behavior == kMACaptionAppearanceBehaviorUseValue) 336 builder.append(" !important"); 337 builder.append(';'); 338 339 return builder.toString(); 340 } 341 342 Color CaptionUserPreferencesMediaAF::captionsEdgeColorForTextColor(const Color& textColor) const 343 { 344 int distanceFromWhite = differenceSquared(textColor, Color::white); 345 int distanceFromBlack = differenceSquared(textColor, Color::black); 346 347 if (distanceFromWhite < distanceFromBlack) 348 return textColor.dark(); 349 350 return textColor.light(); 351 } 352 353 String CaptionUserPreferencesMediaAF::cssPropertyWithTextEdgeColor(CSSPropertyID id, const String& value, const Color& textColor, bool important) const 354 { 355 StringBuilder builder; 356 357 builder.append(getPropertyNameString(id)); 358 builder.append(':'); 359 builder.append(value); 360 builder.append(' '); 361 builder.append(captionsEdgeColorForTextColor(textColor).serialized()); 362 if (important) 363 builder.append(" !important"); 364 builder.append(';'); 365 366 return builder.toString(); 367 } 368 369 String CaptionUserPreferencesMediaAF::colorPropertyCSS(CSSPropertyID id, const Color& color, bool important) const 370 { 371 StringBuilder builder; 372 373 builder.append(getPropertyNameString(id)); 374 builder.append(':'); 375 builder.append(color.serialized()); 376 if (important) 377 builder.append(" !important"); 378 builder.append(';'); 379 380 return builder.toString(); 381 } 382 383 String CaptionUserPreferencesMediaAF::captionsTextEdgeCSS() const 384 { 385 DEFINE_STATIC_LOCAL(const String, edgeStyleRaised, (" -.05em -.05em 0 ", String::ConstructFromLiteral)); 386 DEFINE_STATIC_LOCAL(const String, edgeStyleDepressed, (" .05em .05em 0 ", String::ConstructFromLiteral)); 387 DEFINE_STATIC_LOCAL(const String, edgeStyleDropShadow, (" .075em .075em 0 ", String::ConstructFromLiteral)); 388 DEFINE_STATIC_LOCAL(const String, edgeStyleUniform, (" .03em ", String::ConstructFromLiteral)); 389 390 bool unused; 391 Color color = captionsTextColor(unused); 392 if (!color.isValid()) 393 color.setNamedColor("black"); 394 color = captionsEdgeColorForTextColor(color); 395 396 MACaptionAppearanceBehavior behavior; 397 MACaptionAppearanceTextEdgeStyle textEdgeStyle = MACaptionAppearanceGetTextEdgeStyle(kMACaptionAppearanceDomainUser, &behavior); 398 switch (textEdgeStyle) { 399 case kMACaptionAppearanceTextEdgeStyleUndefined: 400 case kMACaptionAppearanceTextEdgeStyleNone: 401 return emptyString(); 402 403 case kMACaptionAppearanceTextEdgeStyleRaised: 404 return cssPropertyWithTextEdgeColor(CSSPropertyTextShadow, edgeStyleRaised, color, behavior == kMACaptionAppearanceBehaviorUseValue); 405 case kMACaptionAppearanceTextEdgeStyleDepressed: 406 return cssPropertyWithTextEdgeColor(CSSPropertyTextShadow, edgeStyleDepressed, color, behavior == kMACaptionAppearanceBehaviorUseValue); 407 case kMACaptionAppearanceTextEdgeStyleDropShadow: 408 return cssPropertyWithTextEdgeColor(CSSPropertyTextShadow, edgeStyleDropShadow, color, behavior == kMACaptionAppearanceBehaviorUseValue); 409 case kMACaptionAppearanceTextEdgeStyleUniform: 410 return cssPropertyWithTextEdgeColor(CSSPropertyWebkitTextStroke, edgeStyleUniform, color, behavior == kMACaptionAppearanceBehaviorUseValue); 411 412 default: 413 ASSERT_NOT_REACHED(); 414 break; 415 } 416 417 return emptyString(); 418 } 419 420 String CaptionUserPreferencesMediaAF::captionsDefaultFontCSS() const 421 { 422 MACaptionAppearanceBehavior behavior; 423 424 RetainPtr<CTFontDescriptorRef> font = adoptCF(MACaptionAppearanceCopyFontDescriptorForStyle(kMACaptionAppearanceDomainUser, &behavior, kMACaptionAppearanceFontStyleDefault)); 425 if (!font) 426 return emptyString(); 427 428 RetainPtr<CFTypeRef> name = adoptCF(CTFontDescriptorCopyAttribute(font.get(), kCTFontNameAttribute)); 429 if (!name) 430 return emptyString(); 431 432 StringBuilder builder; 433 434 builder.append(getPropertyNameString(CSSPropertyFontFamily)); 435 builder.append(": \""); 436 builder.append(static_cast<CFStringRef>(name.get())); 437 builder.append('"'); 438 if (behavior == kMACaptionAppearanceBehaviorUseValue) 439 builder.append(" !important"); 440 builder.append(';'); 441 442 return builder.toString(); 210 443 } 211 444 … … 275 508 #endif // HAVE(MEDIA_ACCESSIBILITY_FRAMEWORK) 276 509 510 String CaptionUserPreferencesMediaAF::captionsStyleSheetOverride() const 511 { 512 if (testingMode()) 513 return CaptionUserPreferences::captionsStyleSheetOverride(); 514 515 StringBuilder captionsOverrideStyleSheet; 516 517 #if HAVE(MEDIA_ACCESSIBILITY_FRAMEWORK) 518 if (!MediaAccessibilityLibrary()) 519 return CaptionUserPreferences::captionsStyleSheetOverride(); 520 521 String captionsColor = captionsTextColorCSS(); 522 String edgeStyle = captionsTextEdgeCSS(); 523 String fontName = captionsDefaultFontCSS(); 524 String background = captionsBackgroundCSS(); 525 if (!background.isEmpty() || !captionsColor.isEmpty() || !edgeStyle.isEmpty() || !fontName.isEmpty()) { 526 captionsOverrideStyleSheet.append(" video::"); 527 captionsOverrideStyleSheet.append(TextTrackCue::cueShadowPseudoId()); 528 captionsOverrideStyleSheet.append('{'); 529 530 if (!background.isEmpty()) 531 captionsOverrideStyleSheet.append(background); 532 if (!captionsColor.isEmpty()) 533 captionsOverrideStyleSheet.append(captionsColor); 534 if (!edgeStyle.isEmpty()) 535 captionsOverrideStyleSheet.append(edgeStyle); 536 if (!fontName.isEmpty()) 537 captionsOverrideStyleSheet.append(fontName); 538 539 captionsOverrideStyleSheet.append('}'); 540 } 541 542 String windowColor = captionsWindowCSS(); 543 String windowCornerRadius = windowRoundedCornerRadiusCSS(); 544 if (!windowColor.isEmpty() || !windowCornerRadius.isEmpty()) { 545 captionsOverrideStyleSheet.append(" video::"); 546 captionsOverrideStyleSheet.append(TextTrackCueBox::textTrackCueBoxShadowPseudoId()); 547 captionsOverrideStyleSheet.append('{'); 548 549 if (!windowColor.isEmpty()) 550 captionsOverrideStyleSheet.append(windowColor); 551 if (!windowCornerRadius.isEmpty()) 552 captionsOverrideStyleSheet.append(windowCornerRadius); 553 554 captionsOverrideStyleSheet.append('}'); 555 } 556 #endif // HAVE(MEDIA_ACCESSIBILITY_FRAMEWORK) 557 558 LOG(Media, "CaptionUserPreferencesMediaAF::captionsStyleSheetOverrideSetting sytle to:\n%s", captionsOverrideStyleSheet.toString().utf8().data()); 559 560 return captionsOverrideStyleSheet.toString(); 561 } 277 562 278 563 static String languageIdentifier(const String& languageCode) … … 351 636 } 352 637 353 String CaptionUserPreferencesMediaAF::platformCaptionsStyleSheet()354 {355 if (!m_captionStyleSheet)356 m_captionStyleSheet = defaultCaptionsStyleSheet();357 358 return m_captionStyleSheet;359 }360 361 638 String CaptionUserPreferencesMediaAF::displayNameForTrack(TextTrack* track) const 362 639 { … … 368 645 CaptionDisplayMode displayMode = captionDisplayMode(); 369 646 bool legacyOverride = mediaElement->webkitClosedCaptionsVisible(); 370 if (displayMode == AlwaysOn && (!userPrefersSubtitles( mediaElement->document()) && !userPrefersCaptions(mediaElement->document()) && !legacyOverride))647 if (displayMode == AlwaysOn && (!userPrefersSubtitles() && !userPrefersCaptions() && !legacyOverride)) 371 648 return 0; 372 649 if (track->kind() != TextTrack::captionsKeyword() && track->kind() != TextTrack::subtitlesKeyword() && track->kind() != TextTrack::forcedKeyword()) … … 428 705 int trackScore = 0; 429 706 430 if (userPrefersCaptions( mediaElement->document())) {707 if (userPrefersCaptions()) { 431 708 // When the user prefers accessiblity tracks, rank is SDH, then CC, then subtitles. 432 709 if (track->kind() == track->subtitlesKeyword()) … … 490 767 Vector<RefPtr<TextTrack>> tracksForMenu; 491 768 HashSet<String> languagesIncluded; 492 bool prefersAccessibilityTracks = userPrefersCaptions( trackList->mediaElement()->document());769 bool prefersAccessibilityTracks = userPrefersCaptions(); 493 770 bool filterTrackList = shouldFilterTrackMenu(); 494 771 … … 572 849 return tracksForMenu; 573 850 } 574 851 575 852 } 576 853 -
trunk/Source/WebCore/page/CaptionUserPreferencesMediaAF.h
r163048 r163073 38 38 class CaptionUserPreferencesMediaAF : public CaptionUserPreferences { 39 39 public: 40 CaptionUserPreferencesMediaAF( );40 CaptionUserPreferencesMediaAF(PageGroup&); 41 41 virtual ~CaptionUserPreferencesMediaAF(); 42 42 43 43 #if HAVE(MEDIA_ACCESSIBILITY_FRAMEWORK) 44 void captionApperenceChanged();45 46 44 virtual CaptionDisplayMode captionDisplayMode() const override; 47 45 virtual void setCaptionDisplayMode(CaptionDisplayMode) override; 48 46 49 virtual bool userPrefersCaptions( Document&) const override;50 virtual bool userPrefersSubtitles( Document&) const override;47 virtual bool userPrefersCaptions() const override; 48 virtual bool userPrefersSubtitles() const override; 51 49 52 50 virtual float captionFontSizeScaleAndImportance(bool&) const override; 53 51 52 virtual void setInterestedInCaptionPreferenceChanges() override; 53 54 54 virtual void setPreferredLanguage(const String&) override; 55 55 virtual Vector<String> preferredLanguages() const override; 56 57 virtual void captionPreferencesChanged() override; 56 58 57 59 bool shouldFilterTrackMenu() const { return true; } … … 60 62 #endif 61 63 62 virtual String platformCaptionsStyleSheet()override;64 virtual String captionsStyleSheetOverride() const override; 63 65 virtual int textTrackSelectionScore(TextTrack*, HTMLMediaElement*) const override; 64 66 virtual Vector<RefPtr<TextTrack>> sortedTrackListForMenu(TextTrackList*) override; … … 66 68 67 69 private: 68 String m_captionStyleSheet; 70 #if HAVE(MEDIA_ACCESSIBILITY_FRAMEWORK) 71 String captionsWindowCSS() const; 72 String captionsBackgroundCSS() const; 73 String captionsTextColorCSS() const; 74 Color captionsTextColor(bool&) const; 75 String captionsDefaultFontCSS() const; 76 Color captionsEdgeColorForTextColor(const Color&) const; 77 String windowRoundedCornerRadiusCSS() const; 78 String captionsTextEdgeCSS() const; 79 String cssPropertyWithTextEdgeColor(CSSPropertyID, const String&, const Color&, bool) const; 80 String colorPropertyCSS(CSSPropertyID, const Color&, bool) const; 81 82 bool m_listeningForPreferenceChanges; 83 #endif 69 84 }; 70 85 -
trunk/Source/WebCore/page/Page.cpp
r163048 r163073 93 93 #include <wtf/text/StringHash.h> 94 94 95 #if ENABLE(VIDEO_TRACK)96 #if (PLATFORM(MAC) && !PLATFORM(IOS)) || HAVE(MEDIA_ACCESSIBILITY_FRAMEWORK)97 #include "CaptionUserPreferencesMediaAF.h"98 #else99 #include "CaptionUserPreferences.h"100 #endif101 #endif102 103 95 namespace WebCore { 104 96 … … 1502 1494 1503 1495 #if ENABLE(VIDEO_TRACK) 1504 CaptionUserPreferences& Page::captionPreferences()1505 {1506 // FIXME: This should not be a singleton.1507 #if (PLATFORM(MAC) && !PLATFORM(IOS)) || HAVE(MEDIA_ACCESSIBILITY_FRAMEWORK)1508 static NeverDestroyed<CaptionUserPreferencesMediaAF> preferences;1509 #else1510 static NeverDestroyed<CaptionUserPreferences> preferences;1511 #endif1512 1513 return preferences;1514 }1515 1516 void Page::updateStyleForAllPagesForCaptionPreferencesChanged()1517 {1518 if (!allPages)1519 return;1520 1521 for (auto page : *allPages)1522 page->captionPreferencesChanged();1523 }1524 1525 1526 1496 void Page::captionPreferencesChanged() 1527 1497 { -
trunk/Source/WebCore/page/Page.h
r163048 r163073 62 62 class BackForwardController; 63 63 class BackForwardClient; 64 class CaptionUserPreferences;65 64 class Chrome; 66 65 class ChromeClient; … … 404 403 405 404 #if ENABLE(VIDEO_TRACK) 406 static void updateStyleForAllPagesForCaptionPreferencesChanged();407 CaptionUserPreferences& captionPreferences();408 405 void captionPreferencesChanged(); 409 406 #endif -
trunk/Source/WebCore/page/PageGroup.cpp
r163048 r163073 43 43 #include <wtf/StdLibExtras.h> 44 44 45 #if ENABLE(VIDEO_TRACK) 46 #if (PLATFORM(MAC) && !PLATFORM(IOS)) || HAVE(MEDIA_ACCESSIBILITY_FRAMEWORK) 47 #include "CaptionUserPreferencesMediaAF.h" 48 #else 49 #include "CaptionUserPreferences.h" 50 #endif 51 #endif 52 45 53 namespace WebCore { 46 54 … … 303 311 } 304 312 313 #if ENABLE(VIDEO_TRACK) 314 void PageGroup::captionPreferencesChanged() 315 { 316 for (auto it = m_pages.begin(), end = m_pages.end(); it != end; ++it) 317 (*it)->captionPreferencesChanged(); 318 pageCache()->markPagesForCaptionPreferencesChanged(); 319 } 320 321 CaptionUserPreferences* PageGroup::captionPreferences() 322 { 323 if (!m_captionPreferences) { 324 #if (PLATFORM(MAC) && !PLATFORM(IOS)) || HAVE(MEDIA_ACCESSIBILITY_FRAMEWORK) 325 m_captionPreferences = std::make_unique<CaptionUserPreferencesMediaAF>(*this); 326 #else 327 m_captionPreferences = std::make_unique<CaptionUserPreferences>(*this); 328 #endif 329 } 330 331 return m_captionPreferences.get(); 332 } 333 #endif 334 305 335 } // namespace WebCore -
trunk/Source/WebCore/page/PageGroup.h
r163048 r163073 45 45 class VisitedLinkProvider; 46 46 class UserContentController; 47 48 #if ENABLE(VIDEO_TRACK) 49 class CaptionPreferencesChangedListener; 50 class CaptionUserPreferences; 51 #endif 47 52 48 53 class PageGroup : public Supplementable<PageGroup> { … … 99 104 GroupSettings& groupSettings() const { return *m_groupSettings; } 100 105 106 #if ENABLE(VIDEO_TRACK) 107 void captionPreferencesChanged(); 108 CaptionUserPreferences* captionPreferences(); 109 #endif 110 101 111 private: 102 112 void addVisitedLink(LinkHash); … … 117 127 118 128 const std::unique_ptr<GroupSettings> m_groupSettings; 129 130 #if ENABLE(VIDEO_TRACK) 131 std::unique_ptr<CaptionUserPreferences> m_captionPreferences; 132 #endif 119 133 }; 120 134 -
trunk/Source/WebCore/testing/InternalSettings.cpp
r163048 r163073 414 414 415 415 #if ENABLE(VIDEO_TRACK) 416 if (!page()) 417 return; 418 CaptionUserPreferences* captionPreferences = page()->group().captionPreferences(); 419 416 420 if (equalIgnoringCase(kind, "Subtitles")) 417 settings()->setShouldDisplaySubtitles(enabled);421 captionPreferences->setUserPrefersSubtitles(enabled); 418 422 else if (equalIgnoringCase(kind, "Captions")) 419 settings()->setShouldDisplayCaptions(enabled);423 captionPreferences->setUserPrefersCaptions(enabled); 420 424 else if (equalIgnoringCase(kind, "TextDescriptions")) 421 settings()->setShouldDisplayTextDescriptions(enabled);425 captionPreferences->setUserPrefersTextDescriptions(enabled); 422 426 else 423 427 ec = SYNTAX_ERR; … … 433 437 434 438 #if ENABLE(VIDEO_TRACK) 439 if (!page()) 440 return false; 441 CaptionUserPreferences* captionPreferences = page()->group().captionPreferences(); 442 435 443 if (equalIgnoringCase(kind, "Subtitles")) 436 return settings()->shouldDisplaySubtitles();444 return captionPreferences->userPrefersSubtitles(); 437 445 if (equalIgnoringCase(kind, "Captions")) 438 return settings()->shouldDisplayCaptions();446 return captionPreferences->userPrefersCaptions(); 439 447 if (equalIgnoringCase(kind, "TextDescriptions")) 440 return settings()->shouldDisplayTextDescriptions();448 return captionPreferences->userPrefersTextDescriptions(); 441 449 442 450 ec = SYNTAX_ERR; -
trunk/Source/WebCore/testing/Internals.cpp
r163048 r163073 282 282 #endif 283 283 #if ENABLE(VIDEO_TRACK) && !PLATFORM(WIN) 284 page-> captionPreferences().setCaptionsStyleSheetOverride(emptyString());285 page-> captionPreferences().setTestingMode(false);284 page->group().captionPreferences()->setCaptionsStyleSheetOverride(emptyString()); 285 page->group().captionPreferences()->setTestingMode(false); 286 286 #endif 287 287 if (!page->mainFrame().editor().isContinuousSpellCheckingEnabled()) … … 303 303 #if ENABLE(VIDEO_TRACK) && !PLATFORM(WIN) 304 304 if (document && document->page()) 305 document->page()-> captionPreferences().setTestingMode(true);305 document->page()->group().captionPreferences()->setTestingMode(true); 306 306 #endif 307 307 … … 2052 2052 2053 2053 #if ENABLE(VIDEO_TRACK) && !PLATFORM(WIN) 2054 return document->page()-> captionPreferences().captionsStyleSheetOverride();2054 return document->page()->group().captionPreferences()->captionsStyleSheetOverride(); 2055 2055 #else 2056 2056 return emptyString(); … … 2067 2067 2068 2068 #if ENABLE(VIDEO_TRACK) && !PLATFORM(WIN) 2069 document->page()-> captionPreferences().setCaptionsStyleSheetOverride(override);2069 document->page()->group().captionPreferences()->setCaptionsStyleSheetOverride(override); 2070 2070 #else 2071 2071 UNUSED_PARAM(override); … … 2082 2082 2083 2083 #if ENABLE(VIDEO_TRACK) && !PLATFORM(WIN) 2084 document->page()-> captionPreferences().setPrimaryAudioTrackLanguageOverride(language);2084 document->page()->group().captionPreferences()->setPrimaryAudioTrackLanguageOverride(language); 2085 2085 #else 2086 2086 UNUSED_PARAM(language); … … 2097 2097 2098 2098 #if ENABLE(VIDEO_TRACK) && !PLATFORM(WIN) 2099 CaptionUserPreferences & captionPreferences = document->page()->captionPreferences();2099 CaptionUserPreferences* captionPreferences = document->page()->group().captionPreferences(); 2100 2100 2101 if (equalIgnoringCase(mode, "Automatic")) { 2102 captionPreferences.setCaptionDisplayMode(CaptionUserPreferences::Automatic); 2103 document->page()->settings().setShouldDisplayCaptions(false); 2104 document->page()->settings().setShouldDisplaySubtitles(false); 2105 } else if (equalIgnoringCase(mode, "ForcedOnly")) { 2106 captionPreferences.setCaptionDisplayMode(CaptionUserPreferences::ForcedOnly); 2107 document->page()->settings().setShouldDisplayCaptions(false); 2108 document->page()->settings().setShouldDisplaySubtitles(false); 2109 } else if (equalIgnoringCase(mode, "AlwaysOn")) 2110 captionPreferences.setCaptionDisplayMode(CaptionUserPreferences::AlwaysOn); 2101 if (equalIgnoringCase(mode, "Automatic")) 2102 captionPreferences->setCaptionDisplayMode(CaptionUserPreferences::Automatic); 2103 else if (equalIgnoringCase(mode, "ForcedOnly")) 2104 captionPreferences->setCaptionDisplayMode(CaptionUserPreferences::ForcedOnly); 2105 else if (equalIgnoringCase(mode, "AlwaysOn")) 2106 captionPreferences->setCaptionDisplayMode(CaptionUserPreferences::AlwaysOn); 2111 2107 else 2112 2108 ec = SYNTAX_ERR;
Note:
See TracChangeset
for help on using the changeset viewer.