Add version checking to webview library loads.
[chromium-blink-merge.git] / ppapi / cpp / view.cc
blobc17b387efce82bab751259a8e2d11a0355190a40
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ppapi/cpp/view.h"
7 #include "ppapi/c/ppb_view.h"
8 #include "ppapi/cpp/module_impl.h"
10 namespace pp {
12 namespace {
14 template <> const char* interface_name<PPB_View_1_0>() {
15 return PPB_VIEW_INTERFACE_1_0;
18 template <> const char* interface_name<PPB_View_1_1>() {
19 return PPB_VIEW_INTERFACE_1_1;
22 template <> const char* interface_name<PPB_View_1_2>() {
23 return PPB_VIEW_INTERFACE_1_2;
26 } // namespace
28 View::View() : Resource() {
31 View::View(PP_Resource view_resource) : Resource(view_resource) {
34 Rect View::GetRect() const {
35 PP_Rect out;
36 if (has_interface<PPB_View_1_2>()) {
37 if (PP_ToBool(get_interface<PPB_View_1_2>()->GetRect(pp_resource(), &out)))
38 return Rect(out);
39 } else if (has_interface<PPB_View_1_1>()) {
40 if (PP_ToBool(get_interface<PPB_View_1_1>()->GetRect(pp_resource(), &out)))
41 return Rect(out);
42 } else if (has_interface<PPB_View_1_0>()) {
43 if (PP_ToBool(get_interface<PPB_View_1_0>()->GetRect(pp_resource(), &out)))
44 return Rect(out);
46 return Rect();
49 bool View::IsFullscreen() const {
50 if (has_interface<PPB_View_1_2>()) {
51 return PP_ToBool(get_interface<PPB_View_1_2>()->IsFullscreen(
52 pp_resource()));
53 } else if (has_interface<PPB_View_1_1>()) {
54 return PP_ToBool(get_interface<PPB_View_1_1>()->IsFullscreen(
55 pp_resource()));
56 } else if (has_interface<PPB_View_1_0>()) {
57 return PP_ToBool(get_interface<PPB_View_1_0>()->IsFullscreen(
58 pp_resource()));
60 return false;
63 bool View::IsVisible() const {
64 if (has_interface<PPB_View_1_2>())
65 return PP_ToBool(get_interface<PPB_View_1_2>()->IsVisible(pp_resource()));
66 else if (has_interface<PPB_View_1_1>())
67 return PP_ToBool(get_interface<PPB_View_1_1>()->IsVisible(pp_resource()));
68 else if (has_interface<PPB_View_1_0>())
69 return PP_ToBool(get_interface<PPB_View_1_0>()->IsVisible(pp_resource()));
70 return false;
73 bool View::IsPageVisible() const {
74 if (has_interface<PPB_View_1_2>()) {
75 return PP_ToBool(get_interface<PPB_View_1_2>()->IsPageVisible(
76 pp_resource()));
77 } else if (has_interface<PPB_View_1_1>()) {
78 return PP_ToBool(get_interface<PPB_View_1_1>()->IsPageVisible(
79 pp_resource()));
80 } else if (has_interface<PPB_View_1_0>()) {
81 return PP_ToBool(get_interface<PPB_View_1_0>()->IsPageVisible(
82 pp_resource()));
84 return true;
87 Rect View::GetClipRect() const {
88 PP_Rect out;
89 if (has_interface<PPB_View_1_2>()) {
90 if (PP_ToBool(get_interface<PPB_View_1_2>()->GetClipRect(pp_resource(),
91 &out)))
92 return Rect(out);
93 } else if (has_interface<PPB_View_1_1>()) {
94 if (PP_ToBool(get_interface<PPB_View_1_1>()->GetClipRect(pp_resource(),
95 &out)))
96 return Rect(out);
97 } else if (has_interface<PPB_View_1_0>()) {
98 if (PP_ToBool(get_interface<PPB_View_1_0>()->GetClipRect(pp_resource(),
99 &out)))
100 return Rect(out);
102 return Rect();
105 float View::GetDeviceScale() const {
106 if (has_interface<PPB_View_1_2>())
107 return get_interface<PPB_View_1_2>()->GetDeviceScale(pp_resource());
108 else if (has_interface<PPB_View_1_1>())
109 return get_interface<PPB_View_1_1>()->GetDeviceScale(pp_resource());
110 return 1.0f;
113 float View::GetCSSScale() const {
114 if (has_interface<PPB_View_1_2>())
115 return get_interface<PPB_View_1_2>()->GetCSSScale(pp_resource());
116 else if (has_interface<PPB_View_1_1>())
117 return get_interface<PPB_View_1_1>()->GetCSSScale(pp_resource());
118 return 1.0f;
121 Point View::GetScrollOffset() const {
122 PP_Point out;
123 if (has_interface<PPB_View_1_2>()) {
124 if (PP_ToBool(get_interface<PPB_View_1_2>()->GetScrollOffset(pp_resource(),
125 &out))) {
126 return Point(out);
129 return Point();
132 } // namespace pp