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

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

Issue 224733011: A sizes attribute parser (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fixed rebase 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 4ed90a3688dc402339954862cd7427270387690c..d0244991593dc047bb2440214a801d234f632d1a 100644
--- a/Source/core/css/MediaValues.cpp
+++ b/Source/core/css/MediaValues.cpp
@@ -5,6 +5,8 @@
#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"
@@ -21,21 +23,29 @@
namespace WebCore {
-static int calculateViewportWidth(LocalFrame* frame)
+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) const
{
ASSERT(frame && frame->view() && frame->document());
int viewportWidth = frame->view()->layoutSize(IncludeScrollbars).width();
return adjustForAbsoluteZoom(viewportWidth, frame->document()->renderView());
}
-static int calculateViewportHeight(LocalFrame* frame)
+int MediaValues::calculateViewportHeight(LocalFrame* frame) const
{
ASSERT(frame && frame->view() && frame->document());
int viewportHeight = frame->view()->layoutSize(IncludeScrollbars).height();
return adjustForAbsoluteZoom(viewportHeight, frame->document()->renderView());
}
-static int calculateDeviceWidth(LocalFrame* frame)
+int MediaValues::calculateDeviceWidth(LocalFrame* frame) const
{
ASSERT(frame && frame->view() && frame->settings() && frame->host());
int deviceWidth = static_cast<int>(screenRect(frame->view()).width());
@@ -44,7 +54,7 @@ static int calculateDeviceWidth(LocalFrame* frame)
return deviceWidth;
}
-static int calculateDeviceHeight(LocalFrame* frame)
+int MediaValues::calculateDeviceHeight(LocalFrame* frame) const
{
ASSERT(frame && frame->view() && frame->settings() && frame->host());
int deviceHeight = static_cast<int>(screenRect(frame->view()).height());
@@ -53,18 +63,18 @@ static int calculateDeviceHeight(LocalFrame* frame)
return deviceHeight;
}
-static bool calculateStrictMode(LocalFrame* frame)
+bool MediaValues::calculateStrictMode(LocalFrame* frame) const
{
ASSERT(frame && frame->document());
return !frame->document()->inQuirksMode();
}
-static float calculateDevicePixelRatio(LocalFrame* frame)
+float MediaValues::calculateDevicePixelRatio(LocalFrame* frame) const
{
return frame->devicePixelRatio();
}
-static int calculateColorBitsPerComponent(LocalFrame* frame)
+int MediaValues::calculateColorBitsPerComponent(LocalFrame* frame) const
{
ASSERT(frame && frame->page() && frame->page()->mainFrame());
if (screenIsMonochrome(frame->page()->mainFrame()->view()))
@@ -72,7 +82,7 @@ static int calculateColorBitsPerComponent(LocalFrame* frame)
return screenDepthPerComponent(frame->view());
}
-static int calculateMonochromeBitsPerComponent(LocalFrame* frame)
+int MediaValues::calculateMonochromeBitsPerComponent(LocalFrame* frame) const
{
ASSERT(frame && frame->page() && frame->page()->mainFrame());
if (screenIsMonochrome(frame->page()->mainFrame()->view()))
@@ -80,31 +90,36 @@ static int calculateMonochromeBitsPerComponent(LocalFrame* frame)
return 0;
}
-static int calculateDefaultFontSize(RenderStyle* style)
+int MediaValues::calculateDefaultFontSize(RenderStyle* style) const
{
return style->fontDescription().specifiedSize();
}
-static bool calculateScanMediaType(LocalFrame* frame)
+int MediaValues::calculateComputedFontSize(RenderStyle* style) const
+{
+ return style->fontDescription().computedSize();
+}
+
+bool MediaValues::calculateScanMediaType(LocalFrame* frame) const
{
ASSERT(frame && frame->view());
// Scan only applies to 'tv' media.
return equalIgnoringCase(frame->view()->mediaType(), "tv");
}
-static bool calculateScreenMediaType(LocalFrame* frame)
+bool MediaValues::calculateScreenMediaType(LocalFrame* frame) const
{
ASSERT(frame && frame->view());
return equalIgnoringCase(frame->view()->mediaType(), "screen");
}
-static bool calculatePrintMediaType(LocalFrame* frame)
+bool MediaValues::calculatePrintMediaType(LocalFrame* frame) const
{
ASSERT(frame && frame->view());
return equalIgnoringCase(frame->view()->mediaType(), "print");
}
-static bool calculateThreeDEnabled(LocalFrame* frame)
+bool MediaValues::calculateThreeDEnabled(LocalFrame* frame) const
{
ASSERT(frame && frame->contentRenderer() && frame->contentRenderer()->compositor());
bool threeDEnabled = false;
@@ -113,7 +128,7 @@ static bool calculateThreeDEnabled(LocalFrame* frame)
return threeDEnabled;
}
-static MediaValues::PointerDeviceType calculateLeastCapablePrimaryPointerDeviceType(LocalFrame* frame)
+MediaValues::PointerDeviceType MediaValues::calculateLeastCapablePrimaryPointerDeviceType(LocalFrame* frame) const
{
ASSERT(frame && frame->settings());
if (frame->settings()->deviceSupportsTouch())
@@ -129,213 +144,4 @@ static MediaValues::PointerDeviceType calculateLeastCapablePrimaryPointerDeviceT
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);
- mediaValues->m_viewportHeight = calculateViewportHeight(frame),
- 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);
- return m_viewportWidth;
-}
-
-int MediaValues::viewportHeight() const
-{
- if (m_mode == DynamicMode)
- return calculateViewportHeight(m_frame);
- 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