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

Side by Side Diff: Source/core/dom/Document.cpp

Issue 23809007: Refactor the viewport code to be more understandable (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 3 months 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/dom/Document.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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) 2001 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org) 5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org)
6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All r ights reserved. 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All r ights reserved.
7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) 7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/)
8 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved. 8 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved.
9 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) 9 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
10 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved. 10 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved.
(...skipping 3020 matching lines...) Expand 10 before | Expand all | Expand 10 after
3031 callback(keyString, valueString, this, data); 3031 callback(keyString, valueString, this, data);
3032 } 3032 }
3033 if (error) 3033 if (error)
3034 reportViewportWarning(this, InvalidKeyValuePairSeparatorError, String(), String()); 3034 reportViewportWarning(this, InvalidKeyValuePairSeparatorError, String(), String());
3035 } 3035 }
3036 3036
3037 void Document::processViewport(const String& features, ViewportArguments::Type o rigin) 3037 void Document::processViewport(const String& features, ViewportArguments::Type o rigin)
3038 { 3038 {
3039 ASSERT(!features.isNull()); 3039 ASSERT(!features.isNull());
3040 3040
3041 // We are adding viewport properties from a legacy meta tag. 3041 if (!page() || !shouldOverrideLegacyViewport(origin))
3042 // The different meta tags have different priorities based on the type regar dless
3043 // of which order they appear in the DOM. The priority is given by the
3044 // ViewportArguments::Type enum. If we process viewport properties with a lo wer
3045 // priority than an already processed meta tag, just ignore it.
3046 if (origin < m_legacyViewportArguments.type)
3047 return; 3042 return;
3048 3043
3049 // Overwrite viewport arguments from previously encountered meta tags. 3044 ViewportArguments newArgumentsFromLegacyTag(origin);
3050 m_legacyViewportArguments = ViewportArguments(origin); 3045 processArguments(features, (void*)&newArgumentsFromLegacyTag, &setViewportFe ature);
3051 3046
3052 processArguments(features, (void*)&m_legacyViewportArguments, &setViewportFe ature); 3047 if (newArgumentsFromLegacyTag.minZoom == ViewportArguments::ValueAuto)
3048 newArgumentsFromLegacyTag.minZoom = 0.25;
3053 3049
3054 if (m_legacyViewportArguments.minZoom == ViewportArguments::ValueAuto) 3050 if (newArgumentsFromLegacyTag.maxZoom == ViewportArguments::ValueAuto) {
3055 m_legacyViewportArguments.minZoom = 0.25; 3051 newArgumentsFromLegacyTag.maxZoom = 5;
3056 3052 newArgumentsFromLegacyTag.minZoom = std::min(newArgumentsFromLegacyTag.m inZoom, float(5));
3057 if (m_legacyViewportArguments.maxZoom == ViewportArguments::ValueAuto) {
3058 m_legacyViewportArguments.maxZoom = 5;
3059 if (m_legacyViewportArguments.minZoom > 5)
3060 m_legacyViewportArguments.minZoom = 5;
3061 } 3053 }
3062 3054
3063 if (m_legacyViewportArguments.maxWidth.isAuto()) { 3055 const Settings& settings = document().page()->settings();
3064 3056
3065 if (m_legacyViewportArguments.zoom == ViewportArguments::ValueAuto) { 3057 if (newArgumentsFromLegacyTag.maxWidth.isAuto()) {
3066 m_legacyViewportArguments.minWidth = Length(ExtendToZoom); 3058 if (newArgumentsFromLegacyTag.zoom == ViewportArguments::ValueAuto) {
3067 m_legacyViewportArguments.maxWidth = Length(page()->settings().layou tFallbackWidth(), Fixed); 3059 newArgumentsFromLegacyTag.minWidth = Length(ExtendToZoom);
3068 } else if (m_legacyViewportArguments.maxHeight.isAuto()) { 3060 newArgumentsFromLegacyTag.maxWidth = Length(settings.layoutFallbackW idth(), Fixed);
3069 m_legacyViewportArguments.minWidth = m_legacyViewportArguments.maxWi dth = Length(ExtendToZoom); 3061 } else if (newArgumentsFromLegacyTag.maxHeight.isAuto()) {
3062 newArgumentsFromLegacyTag.minWidth = Length(ExtendToZoom);
3063 newArgumentsFromLegacyTag.maxWidth = Length(ExtendToZoom);
3070 } 3064 }
3071 } 3065 }
3072 3066
3073 if (page() && page()->settings().viewportMetaZeroValuesQuirk() && m_legacyVi ewportArguments.type == ViewportArguments::ViewportMeta 3067 if (settings.viewportMetaZeroValuesQuirk()
3074 && m_legacyViewportArguments.maxWidth.type() == ViewportPercentageWidth && !static_cast<int>(m_legacyViewportArguments.zoom)) 3068 && newArgumentsFromLegacyTag.type == ViewportArguments::ViewportMeta
3075 m_legacyViewportArguments.zoom = 1.0; 3069 && newArgumentsFromLegacyTag.maxWidth.type() == ViewportPercentageWidth
3070 && !static_cast<int>(newArgumentsFromLegacyTag.zoom)) {
3071 newArgumentsFromLegacyTag.zoom = 1.0;
3072 }
3076 3073
3077 // When no author style for @viewport is present, and a meta tag for definin g the 3074 setViewportArguments(newArgumentsFromLegacyTag);
3078 // viewport is present, apply the meta tag viewport arguments instead of the UA styles. 3075 }
3079 if (m_viewportArguments.type != ViewportArguments::AuthorStyleSheet) { 3076
3080 m_viewportArguments = m_legacyViewportArguments; 3077 void Document::setViewportArguments(const ViewportArguments& viewportArguments)
3081 updateViewportArguments(); 3078 {
3079 if (viewportArguments.isLegacyViewportType()) {
3080 m_legacyViewportArguments = viewportArguments;
3081
3082 // When no author style for @viewport is present, and a meta tag for def ining
3083 // the viewport is, apply the meta tag viewport instead of the UA styles .
3084 if (m_viewportArguments.type == ViewportArguments::AuthorStyleSheet)
3085 return;
3086 m_viewportArguments = viewportArguments;
3087 } else {
3088 // If the legacy viewport tag has higher priority than the cascaded @vie wport
3089 // descriptors, use the values from the legacy tag.
3090 if (!shouldOverrideLegacyViewport(viewportArguments.type))
3091 m_viewportArguments = m_legacyViewportArguments;
3092 else
3093 m_viewportArguments = viewportArguments;
3082 } 3094 }
3095
3096 updateViewportArguments();
3083 } 3097 }
3084 3098
3085 void Document::updateViewportArguments() 3099 void Document::updateViewportArguments()
3086 { 3100 {
3087 if (page() && page()->mainFrame() == frame()) { 3101 if (page() && page()->mainFrame() == frame()) {
3088 #ifndef NDEBUG 3102 #ifndef NDEBUG
3089 m_didDispatchViewportPropertiesChanged = true; 3103 m_didDispatchViewportPropertiesChanged = true;
3090 #endif 3104 #endif
3091 page()->chrome().dispatchViewportPropertiesDidChange(m_viewportArguments ); 3105 page()->chrome().dispatchViewportPropertiesDidChange(m_viewportArguments );
3092 } 3106 }
(...skipping 2342 matching lines...) Expand 10 before | Expand all | Expand 10 after
5435 { 5449 {
5436 return DocumentLifecycleNotifier::create(this); 5450 return DocumentLifecycleNotifier::create(this);
5437 } 5451 }
5438 5452
5439 DocumentLifecycleNotifier* Document::lifecycleNotifier() 5453 DocumentLifecycleNotifier* Document::lifecycleNotifier()
5440 { 5454 {
5441 return static_cast<DocumentLifecycleNotifier*>(ScriptExecutionContext::lifec ycleNotifier()); 5455 return static_cast<DocumentLifecycleNotifier*>(ScriptExecutionContext::lifec ycleNotifier());
5442 } 5456 }
5443 5457
5444 } // namespace WebCore 5458 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/dom/Document.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698