OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ppapi/cpp/view.h" | 5 #include "ppapi/cpp/view.h" |
6 | 6 |
7 #include "ppapi/c/ppb_view.h" | 7 #include "ppapi/c/ppb_view.h" |
8 #include "ppapi/cpp/module_impl.h" | 8 #include "ppapi/cpp/module_impl.h" |
9 | 9 |
10 namespace pp { | 10 namespace pp { |
11 | 11 |
12 namespace { | 12 namespace { |
13 | 13 |
14 template <> const char* interface_name<PPB_View_1_0>() { | 14 template <> const char* interface_name<PPB_View_1_0>() { |
15 return PPB_VIEW_INTERFACE_1_0; | 15 return PPB_VIEW_INTERFACE_1_0; |
16 } | 16 } |
17 | 17 |
| 18 template <> const char* interface_name<PPB_View_1_1>() { |
| 19 return PPB_VIEW_INTERFACE_1_1; |
| 20 } |
| 21 |
18 } // namespace | 22 } // namespace |
19 | 23 |
20 View::View() : Resource() { | 24 View::View() : Resource() { |
21 } | 25 } |
22 | 26 |
23 View::View(PP_Resource view_resource) : Resource(view_resource) { | 27 View::View(PP_Resource view_resource) : Resource(view_resource) { |
24 } | 28 } |
25 | 29 |
26 Rect View::GetRect() const { | 30 Rect View::GetRect() const { |
27 if (!has_interface<PPB_View_1_0>()) | |
28 return Rect(); | |
29 PP_Rect out; | 31 PP_Rect out; |
30 if (PP_ToBool(get_interface<PPB_View_1_0>()->GetRect(pp_resource(), &out))) | 32 if (has_interface<PPB_View_1_1>()) { |
31 return Rect(out); | 33 if (PP_ToBool(get_interface<PPB_View_1_1>()->GetRect(pp_resource(), &out))) |
| 34 return Rect(out); |
| 35 } else if (has_interface<PPB_View_1_0>()) { |
| 36 if (PP_ToBool(get_interface<PPB_View_1_0>()->GetRect(pp_resource(), &out))) |
| 37 return Rect(out); |
| 38 } |
32 return Rect(); | 39 return Rect(); |
33 } | 40 } |
34 | 41 |
35 bool View::IsFullscreen() const { | 42 bool View::IsFullscreen() const { |
36 if (!has_interface<PPB_View_1_0>()) | 43 if (has_interface<PPB_View_1_1>()) { |
37 return false; | 44 return PP_ToBool(get_interface<PPB_View_1_1>()->IsFullscreen( |
38 return PP_ToBool(get_interface<PPB_View_1_0>()->IsFullscreen(pp_resource())); | 45 pp_resource())); |
| 46 } else if (has_interface<PPB_View_1_0>()) { |
| 47 return PP_ToBool(get_interface<PPB_View_1_0>()->IsFullscreen( |
| 48 pp_resource())); |
| 49 } |
| 50 return false; |
39 } | 51 } |
40 | 52 |
41 bool View::IsVisible() const { | 53 bool View::IsVisible() const { |
42 if (!has_interface<PPB_View_1_0>()) | 54 if (has_interface<PPB_View_1_1>()) |
43 return false; | 55 return PP_ToBool(get_interface<PPB_View_1_1>()->IsVisible(pp_resource())); |
44 return PP_ToBool(get_interface<PPB_View_1_0>()->IsVisible(pp_resource())); | 56 else if (has_interface<PPB_View_1_0>()) |
| 57 return PP_ToBool(get_interface<PPB_View_1_0>()->IsVisible(pp_resource())); |
| 58 return false; |
45 } | 59 } |
46 | 60 |
47 bool View::IsPageVisible() const { | 61 bool View::IsPageVisible() const { |
48 if (!has_interface<PPB_View_1_0>()) | 62 if (has_interface<PPB_View_1_1>()) { |
49 return true; | 63 return PP_ToBool(get_interface<PPB_View_1_1>()->IsPageVisible( |
50 return PP_ToBool(get_interface<PPB_View_1_0>()->IsPageVisible(pp_resource())); | 64 pp_resource())); |
| 65 } else if (has_interface<PPB_View_1_0>()) { |
| 66 return PP_ToBool(get_interface<PPB_View_1_0>()->IsPageVisible( |
| 67 pp_resource())); |
| 68 } |
| 69 return true; |
51 } | 70 } |
52 | 71 |
53 Rect View::GetClipRect() const { | 72 Rect View::GetClipRect() const { |
54 if (!has_interface<PPB_View_1_0>()) | |
55 return Rect(); | |
56 PP_Rect out; | 73 PP_Rect out; |
57 if (PP_ToBool(get_interface<PPB_View_1_0>()->GetClipRect(pp_resource(), | 74 if (has_interface<PPB_View_1_1>()) { |
58 &out))) | 75 if (PP_ToBool(get_interface<PPB_View_1_1>()->GetClipRect(pp_resource(), |
59 return Rect(out); | 76 &out))) |
| 77 return Rect(out); |
| 78 } else if (has_interface<PPB_View_1_0>()) { |
| 79 if (PP_ToBool(get_interface<PPB_View_1_0>()->GetClipRect(pp_resource(), |
| 80 &out))) |
| 81 return Rect(out); |
| 82 } |
60 return Rect(); | 83 return Rect(); |
61 } | 84 } |
62 | 85 |
| 86 float View::GetDeviceScale() const { |
| 87 if (has_interface<PPB_View_1_1>()) |
| 88 return get_interface<PPB_View_1_1>()->GetDeviceScale(pp_resource()); |
| 89 return 1.0f; |
| 90 } |
| 91 |
| 92 float View::GetCSSScale() const { |
| 93 if (has_interface<PPB_View_1_1>()) |
| 94 return get_interface<PPB_View_1_1>()->GetCSSScale(pp_resource()); |
| 95 return 1.0f; |
| 96 } |
| 97 |
63 } // namespace pp | 98 } // namespace pp |
OLD | NEW |