blob: 0a5d1d09e0c58f34c779c20310022c21c31409fd [file] [log] [blame]
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "core/css/MediaValuesDynamic.h"
#include "core/css/CSSPrimitiveValue.h"
#include "core/css/CSSResolutionUnits.h"
#include "core/css/CSSToLengthConversionData.h"
#include "core/css/MediaValuesCached.h"
#include "core/dom/Document.h"
#include "core/frame/LocalFrame.h"
namespace blink {
MediaValues* MediaValuesDynamic::Create(Document& document) {
return MediaValuesDynamic::Create(document.GetFrameOfMasterDocument());
}
MediaValues* MediaValuesDynamic::Create(LocalFrame* frame) {
if (!frame || !frame->View() || !frame->GetDocument() ||
!frame->GetDocument()->GetLayoutView())
return MediaValuesCached::Create();
return new MediaValuesDynamic(frame);
}
MediaValuesDynamic::MediaValuesDynamic(LocalFrame* frame)
: frame_(frame),
viewport_dimensions_overridden_(false),
viewport_width_override_(0),
viewport_height_override_(0) {
DCHECK(frame_);
}
MediaValuesDynamic::MediaValuesDynamic(LocalFrame* frame,
bool overridden_viewport_dimensions,
double viewport_width,
double viewport_height)
: frame_(frame),
viewport_dimensions_overridden_(overridden_viewport_dimensions),
viewport_width_override_(viewport_width),
viewport_height_override_(viewport_height) {
DCHECK(frame_);
}
MediaValues* MediaValuesDynamic::Copy() const {
return new MediaValuesDynamic(frame_, viewport_dimensions_overridden_,
viewport_width_override_,
viewport_height_override_);
}
bool MediaValuesDynamic::ComputeLength(double value,
CSSPrimitiveValue::UnitType type,
int& result) const {
return MediaValues::ComputeLength(
value, type, CalculateDefaultFontSize(frame_),
CalculateViewportWidth(frame_), CalculateViewportHeight(frame_), result);
}
bool MediaValuesDynamic::ComputeLength(double value,
CSSPrimitiveValue::UnitType type,
double& result) const {
return MediaValues::ComputeLength(
value, type, CalculateDefaultFontSize(frame_),
CalculateViewportWidth(frame_), CalculateViewportHeight(frame_), result);
}
double MediaValuesDynamic::ViewportWidth() const {
if (viewport_dimensions_overridden_)
return viewport_width_override_;
return CalculateViewportWidth(frame_);
}
double MediaValuesDynamic::ViewportHeight() const {
if (viewport_dimensions_overridden_)
return viewport_height_override_;
return CalculateViewportHeight(frame_);
}
int MediaValuesDynamic::DeviceWidth() const {
return CalculateDeviceWidth(frame_);
}
int MediaValuesDynamic::DeviceHeight() const {
return CalculateDeviceHeight(frame_);
}
float MediaValuesDynamic::DevicePixelRatio() const {
return CalculateDevicePixelRatio(frame_);
}
int MediaValuesDynamic::ColorBitsPerComponent() const {
return CalculateColorBitsPerComponent(frame_);
}
int MediaValuesDynamic::MonochromeBitsPerComponent() const {
return CalculateMonochromeBitsPerComponent(frame_);
}
PointerType MediaValuesDynamic::PrimaryPointerType() const {
return CalculatePrimaryPointerType(frame_);
}
int MediaValuesDynamic::AvailablePointerTypes() const {
return CalculateAvailablePointerTypes(frame_);
}
HoverType MediaValuesDynamic::PrimaryHoverType() const {
return CalculatePrimaryHoverType(frame_);
}
int MediaValuesDynamic::AvailableHoverTypes() const {
return CalculateAvailableHoverTypes(frame_);
}
bool MediaValuesDynamic::ThreeDEnabled() const {
return CalculateThreeDEnabled(frame_);
}
const String MediaValuesDynamic::MediaType() const {
return CalculateMediaType(frame_);
}
WebDisplayMode MediaValuesDynamic::DisplayMode() const {
return CalculateDisplayMode(frame_);
}
bool MediaValuesDynamic::StrictMode() const {
return CalculateStrictMode(frame_);
}
DisplayShape MediaValuesDynamic::GetDisplayShape() const {
return CalculateDisplayShape(frame_);
}
ColorSpaceGamut MediaValuesDynamic::ColorGamut() const {
return CalculateColorGamut(frame_);
}
Document* MediaValuesDynamic::GetDocument() const {
return frame_->GetDocument();
}
bool MediaValuesDynamic::HasValues() const {
return frame_;
}
void MediaValuesDynamic::Trace(blink::Visitor* visitor) {
visitor->Trace(frame_);
MediaValues::Trace(visitor);
}
void MediaValuesDynamic::OverrideViewportDimensions(double width,
double height) {
viewport_dimensions_overridden_ = true;
viewport_width_override_ = width;
viewport_height_override_ = height;
}
} // namespace blink