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

Unified Diff: Source/core/css/MediaValues.cpp

Issue 240063003: Revert "A sizes attribute parser" (https://codereview.chromium.org/224733011) (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/css/MediaValues.h ('k') | Source/core/css/MediaValuesCached.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/css/MediaValues.cpp
diff --git a/Source/core/css/MediaValues.cpp b/Source/core/css/MediaValues.cpp
index 8527f4f372ba765961a37b5893717b76177446df..1291d4e51a34e70d3dd607b0a9a9f28d9ae40516 100644
--- a/Source/core/css/MediaValues.cpp
+++ b/Source/core/css/MediaValues.cpp
@@ -5,8 +5,6 @@
#include "config.h"
#include "core/css/MediaValues.h"
-#include "core/css/MediaValuesCached.h"
-#include "core/css/MediaValuesDynamic.h"
#include "core/dom/Document.h"
#include "core/dom/Element.h"
#include "core/frame/FrameHost.h"
@@ -23,29 +21,21 @@
namespace WebCore {
-Document* MediaValues::getExecutingDocument(Document& document)
-{
- Document* executingDocument = document.importsController() ? document.importsController()->master() : &document;
- ASSERT(executingDocument);
- ASSERT(executingDocument->renderer());
- return executingDocument;
-}
-
-int MediaValues::calculateViewportWidth(LocalFrame* frame, RenderStyle* style) const
+static int calculateViewportWidth(LocalFrame* frame, RenderStyle* style)
{
ASSERT(frame && frame->view() && style);
int viewportWidth = frame->view()->layoutSize(IncludeScrollbars).width();
return adjustForAbsoluteZoom(viewportWidth, style);
}
-int MediaValues::calculateViewportHeight(LocalFrame* frame, RenderStyle* style) const
+static int calculateViewportHeight(LocalFrame* frame, RenderStyle* style)
{
ASSERT(frame && frame->view() && style);
int viewportHeight = frame->view()->layoutSize(IncludeScrollbars).height();
return adjustForAbsoluteZoom(viewportHeight, style);
}
-int MediaValues::calculateDeviceWidth(LocalFrame* frame) const
+static int calculateDeviceWidth(LocalFrame* frame)
{
ASSERT(frame && frame->view() && frame->settings() && frame->host());
int deviceWidth = static_cast<int>(screenRect(frame->view()).width());
@@ -54,7 +44,7 @@ int MediaValues::calculateDeviceWidth(LocalFrame* frame) const
return deviceWidth;
}
-int MediaValues::calculateDeviceHeight(LocalFrame* frame) const
+static int calculateDeviceHeight(LocalFrame* frame)
{
ASSERT(frame && frame->view() && frame->settings() && frame->host());
int deviceHeight = static_cast<int>(screenRect(frame->view()).height());
@@ -63,18 +53,18 @@ int MediaValues::calculateDeviceHeight(LocalFrame* frame) const
return deviceHeight;
}
-bool MediaValues::calculateStrictMode(LocalFrame* frame) const
+static bool calculateStrictMode(LocalFrame* frame)
{
ASSERT(frame && frame->document());
return !frame->document()->inQuirksMode();
}
-float MediaValues::calculateDevicePixelRatio(LocalFrame* frame) const
+static float calculateDevicePixelRatio(LocalFrame* frame)
{
return frame->devicePixelRatio();
}
-int MediaValues::calculateColorBitsPerComponent(LocalFrame* frame) const
+static int calculateColorBitsPerComponent(LocalFrame* frame)
{
ASSERT(frame && frame->page() && frame->page()->mainFrame());
if (screenIsMonochrome(frame->page()->mainFrame()->view()))
@@ -82,7 +72,7 @@ int MediaValues::calculateColorBitsPerComponent(LocalFrame* frame) const
return screenDepthPerComponent(frame->view());
}
-int MediaValues::calculateMonochromeBitsPerComponent(LocalFrame* frame) const
+static int calculateMonochromeBitsPerComponent(LocalFrame* frame)
{
ASSERT(frame && frame->page() && frame->page()->mainFrame());
if (screenIsMonochrome(frame->page()->mainFrame()->view()))
@@ -90,51 +80,31 @@ int MediaValues::calculateMonochromeBitsPerComponent(LocalFrame* frame) const
return 0;
}
-int MediaValues::calculateDefaultFontSize(RenderStyle* style) const
+static int calculateDefaultFontSize(RenderStyle* style)
{
return style->fontDescription().specifiedSize();
}
-int MediaValues::calculateComputedFontSize(RenderStyle* style) const
-{
- return style->fontDescription().computedSize();
-}
-
-bool MediaValues::calculateHasXHeight(RenderStyle* style) const
-{
- return style->fontMetrics().hasXHeight();
-}
-
-double MediaValues::calculateXHeight(RenderStyle* style) const
-{
- return style->fontMetrics().xHeight();
-}
-
-double MediaValues::calculateZeroWidth(RenderStyle* style) const
-{
- return style->fontMetrics().zeroWidth();
-}
-
-bool MediaValues::calculateScanMediaType(LocalFrame* frame) const
+static bool calculateScanMediaType(LocalFrame* frame)
{
ASSERT(frame && frame->view());
// Scan only applies to 'tv' media.
return equalIgnoringCase(frame->view()->mediaType(), "tv");
}
-bool MediaValues::calculateScreenMediaType(LocalFrame* frame) const
+static bool calculateScreenMediaType(LocalFrame* frame)
{
ASSERT(frame && frame->view());
return equalIgnoringCase(frame->view()->mediaType(), "screen");
}
-bool MediaValues::calculatePrintMediaType(LocalFrame* frame) const
+static bool calculatePrintMediaType(LocalFrame* frame)
{
ASSERT(frame && frame->view());
return equalIgnoringCase(frame->view()->mediaType(), "print");
}
-bool MediaValues::calculateThreeDEnabled(LocalFrame* frame) const
+static bool calculateThreeDEnabled(LocalFrame* frame)
{
ASSERT(frame && frame->contentRenderer() && frame->contentRenderer()->compositor());
bool threeDEnabled = false;
@@ -143,7 +113,7 @@ bool MediaValues::calculateThreeDEnabled(LocalFrame* frame) const
return threeDEnabled;
}
-MediaValues::PointerDeviceType MediaValues::calculateLeastCapablePrimaryPointerDeviceType(LocalFrame* frame) const
+static MediaValues::PointerDeviceType calculateLeastCapablePrimaryPointerDeviceType(LocalFrame* frame)
{
ASSERT(frame && frame->settings());
if (frame->settings()->deviceSupportsTouch())
@@ -159,4 +129,213 @@ MediaValues::PointerDeviceType MediaValues::calculateLeastCapablePrimaryPointerD
return MediaValues::UnknownPointer;
}
+PassRefPtr<MediaValues> MediaValues::create(MediaValuesMode mode,
+ int viewportWidth,
+ int viewportHeight,
+ int deviceWidth,
+ int deviceHeight,
+ float devicePixelRatio,
+ int colorBitsPerComponent,
+ int monochromeBitsPerComponent,
+ PointerDeviceType pointer,
+ int defaultFontSize,
+ bool threeDEnabled,
+ bool scanMediaType,
+ bool screenMediaType,
+ bool printMediaType,
+ bool strictMode)
+{
+ ASSERT(mode == CachingMode);
+ RefPtr<MediaValues> mediaValues = adoptRef(new MediaValues(0, nullptr, mode));
+ mediaValues->m_viewportWidth = viewportWidth;
+ mediaValues->m_viewportHeight = viewportHeight;
+ mediaValues->m_deviceWidth = deviceWidth;
+ mediaValues->m_deviceHeight = deviceHeight;
+ mediaValues->m_devicePixelRatio = devicePixelRatio;
+ mediaValues->m_colorBitsPerComponent = colorBitsPerComponent;
+ mediaValues->m_monochromeBitsPerComponent = monochromeBitsPerComponent;
+ mediaValues->m_pointer = pointer;
+ mediaValues->m_defaultFontSize = defaultFontSize;
+ mediaValues->m_threeDEnabled = threeDEnabled;
+ mediaValues->m_scanMediaType = scanMediaType;
+ mediaValues->m_screenMediaType = screenMediaType;
+ mediaValues->m_printMediaType = printMediaType;
+ mediaValues->m_strictMode = strictMode;
+
+ return mediaValues;
+}
+
+PassRefPtr<MediaValues> MediaValues::create(LocalFrame* frame, RenderStyle* style, MediaValuesMode mode)
+{
+ ASSERT(frame && style);
+ RefPtr<MediaValues> mediaValues;
+ mediaValues = adoptRef(new MediaValues(frame, style, mode));
+ if (mode == CachingMode) {
+ mediaValues->m_viewportWidth = calculateViewportWidth(frame, style);
+ mediaValues->m_viewportHeight = calculateViewportHeight(frame, style),
+ mediaValues->m_deviceWidth = calculateDeviceWidth(frame),
+ mediaValues->m_deviceHeight = calculateDeviceHeight(frame),
+ mediaValues->m_devicePixelRatio = calculateDevicePixelRatio(frame),
+ mediaValues->m_colorBitsPerComponent = calculateColorBitsPerComponent(frame),
+ mediaValues->m_monochromeBitsPerComponent = calculateMonochromeBitsPerComponent(frame),
+ mediaValues->m_pointer = calculateLeastCapablePrimaryPointerDeviceType(frame),
+ mediaValues->m_defaultFontSize = calculateDefaultFontSize(style),
+ mediaValues->m_threeDEnabled = calculateThreeDEnabled(frame),
+ mediaValues->m_scanMediaType = calculateScanMediaType(frame),
+ mediaValues->m_screenMediaType = calculateScreenMediaType(frame),
+ mediaValues->m_printMediaType = calculatePrintMediaType(frame),
+ mediaValues->m_strictMode = calculateStrictMode(frame);
+
+ mediaValues->m_style.clear();
+ mediaValues->m_frame = 0;
+ }
+
+ return mediaValues;
+}
+
+PassRefPtr<MediaValues> MediaValues::create(Document* document, MediaValuesMode mode)
+{
+ ASSERT(document);
+ Document* executingDocument = document->importsController() ? document->importsController()->master() : document;
+ ASSERT(executingDocument->frame());
+ ASSERT(executingDocument->renderer());
+ ASSERT(executingDocument->renderer()->style());
+ LocalFrame* frame = executingDocument->frame();
+ RenderStyle* style = executingDocument->renderer()->style();
+
+ return MediaValues::create(frame, style, mode);
+}
+
+PassRefPtr<MediaValues> MediaValues::copy() const
+{
+ ASSERT(m_mode == CachingMode && !m_style.get() && !m_frame);
+ RefPtr<MediaValues> mediaValues = adoptRef(new MediaValues(0, nullptr, m_mode));
+ mediaValues->m_viewportWidth = m_viewportWidth;
+ mediaValues->m_viewportHeight = m_viewportHeight;
+ mediaValues->m_deviceWidth = m_deviceWidth;
+ mediaValues->m_deviceHeight = m_deviceHeight;
+ mediaValues->m_devicePixelRatio = m_devicePixelRatio;
+ mediaValues->m_colorBitsPerComponent = m_colorBitsPerComponent;
+ mediaValues->m_monochromeBitsPerComponent = m_monochromeBitsPerComponent;
+ mediaValues->m_pointer = m_pointer;
+ mediaValues->m_defaultFontSize = m_defaultFontSize;
+ mediaValues->m_threeDEnabled = m_threeDEnabled;
+ mediaValues->m_scanMediaType = m_scanMediaType;
+ mediaValues->m_screenMediaType = m_screenMediaType;
+ mediaValues->m_printMediaType = m_printMediaType;
+ mediaValues->m_strictMode = m_strictMode;
+
+ return mediaValues;
+}
+
+bool MediaValues::isSafeToSendToAnotherThread() const
+{
+ return (!m_frame && !m_style && m_mode == CachingMode && hasOneRef());
+}
+
+int MediaValues::viewportWidth() const
+{
+ if (m_mode == DynamicMode)
+ return calculateViewportWidth(m_frame, m_style.get());
+ return m_viewportWidth;
+}
+
+int MediaValues::viewportHeight() const
+{
+ if (m_mode == DynamicMode)
+ return calculateViewportHeight(m_frame, m_style.get());
+ return m_viewportHeight;
+}
+
+int MediaValues::deviceWidth() const
+{
+ if (m_mode == DynamicMode)
+ return calculateDeviceWidth(m_frame);
+ return m_deviceWidth;
+}
+
+int MediaValues::deviceHeight() const
+{
+ if (m_mode == DynamicMode)
+ return calculateDeviceHeight(m_frame);
+ return m_deviceHeight;
+}
+
+float MediaValues::devicePixelRatio() const
+{
+ if (m_mode == DynamicMode)
+ return calculateDevicePixelRatio(m_frame);
+ return m_devicePixelRatio;
+}
+
+int MediaValues::colorBitsPerComponent() const
+{
+ if (m_mode == DynamicMode)
+ return calculateColorBitsPerComponent(m_frame);
+ return m_colorBitsPerComponent;
+}
+
+int MediaValues::monochromeBitsPerComponent() const
+{
+ if (m_mode == DynamicMode)
+ return calculateMonochromeBitsPerComponent(m_frame);
+ return m_monochromeBitsPerComponent;
+}
+
+MediaValues::PointerDeviceType MediaValues::pointer() const
+{
+ if (m_mode == DynamicMode)
+ return calculateLeastCapablePrimaryPointerDeviceType(m_frame);
+ return m_pointer;
+}
+
+int MediaValues::defaultFontSize() const
+{
+ if (m_mode == DynamicMode)
+ return calculateDefaultFontSize(m_style.get());
+ return m_defaultFontSize;
+}
+
+bool MediaValues::threeDEnabled() const
+{
+ if (m_mode == DynamicMode)
+ return calculateThreeDEnabled(m_frame);
+ return m_threeDEnabled;
+}
+
+bool MediaValues::scanMediaType() const
+{
+ if (m_mode == DynamicMode)
+ return calculateScanMediaType(m_frame);
+ return m_scanMediaType;
+}
+
+bool MediaValues::screenMediaType() const
+{
+ if (m_mode == DynamicMode)
+ return calculateScreenMediaType(m_frame);
+ return m_screenMediaType;
+}
+
+bool MediaValues::printMediaType() const
+{
+ if (m_mode == DynamicMode)
+ return calculatePrintMediaType(m_frame);
+ return m_printMediaType;
+}
+
+bool MediaValues::strictMode() const
+{
+ if (m_mode == DynamicMode)
+ return calculateStrictMode(m_frame);
+ return m_strictMode;
+}
+
+Document* MediaValues::document() const
+{
+ if (!m_frame)
+ return 0;
+ return m_frame->document();
+}
+
} // namespace
« no previous file with comments | « Source/core/css/MediaValues.h ('k') | Source/core/css/MediaValuesCached.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698