Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 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. |
| 4 | |
| 5 | #include "ppapi/cpp/view.h" |
| 6 | |
| 7 | #include "ppapi/c/ppb_view.h" |
| 8 | #include "ppapi/cpp/module_impl.h" |
| 9 | |
| 10 | namespace pp { |
| 11 | |
| 12 | namespace { |
| 13 | |
| 14 | template <> const char* interface_name<PPB_View_1_0>() { |
| 15 | return PPB_VIEW_INTERFACE_1_0; |
| 16 | } |
| 17 | |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 18 | template <> const char* interface_name<PPB_View_1_1>() { |
| 19 | return PPB_VIEW_INTERFACE_1_1; |
| 20 | } |
| 21 | |
Torne (Richard Coles) | 6d86b77 | 2014-06-25 10:30:53 +0100 | [diff] [blame] | 22 | template <> const char* interface_name<PPB_View_1_2>() { |
| 23 | return PPB_VIEW_INTERFACE_1_2; |
| 24 | } |
| 25 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 26 | } // namespace |
| 27 | |
| 28 | View::View() : Resource() { |
| 29 | } |
| 30 | |
| 31 | View::View(PP_Resource view_resource) : Resource(view_resource) { |
| 32 | } |
| 33 | |
| 34 | Rect View::GetRect() const { |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 35 | PP_Rect out; |
Torne (Richard Coles) | 6d86b77 | 2014-06-25 10:30:53 +0100 | [diff] [blame] | 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>()) { |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 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); |
| 45 | } |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 46 | return Rect(); |
| 47 | } |
| 48 | |
| 49 | bool View::IsFullscreen() const { |
Torne (Richard Coles) | 6d86b77 | 2014-06-25 10:30:53 +0100 | [diff] [blame] | 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>()) { |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 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())); |
| 59 | } |
| 60 | return false; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | bool View::IsVisible() const { |
Torne (Richard Coles) | 6d86b77 | 2014-06-25 10:30:53 +0100 | [diff] [blame] | 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>()) |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 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; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | bool View::IsPageVisible() const { |
Torne (Richard Coles) | 6d86b77 | 2014-06-25 10:30:53 +0100 | [diff] [blame] | 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>()) { |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 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())); |
| 83 | } |
| 84 | return true; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | Rect View::GetClipRect() const { |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 88 | PP_Rect out; |
Torne (Richard Coles) | 6d86b77 | 2014-06-25 10:30:53 +0100 | [diff] [blame] | 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>()) { |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 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); |
| 101 | } |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 102 | return Rect(); |
| 103 | } |
| 104 | |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 105 | float View::GetDeviceScale() const { |
Torne (Richard Coles) | 6d86b77 | 2014-06-25 10:30:53 +0100 | [diff] [blame] | 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>()) |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 109 | return get_interface<PPB_View_1_1>()->GetDeviceScale(pp_resource()); |
| 110 | return 1.0f; |
| 111 | } |
| 112 | |
| 113 | float View::GetCSSScale() const { |
Torne (Richard Coles) | 6d86b77 | 2014-06-25 10:30:53 +0100 | [diff] [blame] | 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>()) |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 117 | return get_interface<PPB_View_1_1>()->GetCSSScale(pp_resource()); |
| 118 | return 1.0f; |
| 119 | } |
| 120 | |
Torne (Richard Coles) | 6d86b77 | 2014-06-25 10:30:53 +0100 | [diff] [blame] | 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); |
| 127 | } |
| 128 | } |
| 129 | return Point(); |
| 130 | } |
| 131 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 132 | } // namespace pp |