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 18 template <> const char* interface_name<PPB_View_1_1>() { 19 return PPB_VIEW_INTERFACE_1_1; 20 } 21 22 } // namespace 23 24 View::View() : Resource() { 25 } 26 27 View::View(PP_Resource view_resource) : Resource(view_resource) { 28 } 29 30 Rect View::GetRect() const { 31 PP_Rect out; 32 if (has_interface<PPB_View_1_1>()) { 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 } 39 return Rect(); 40 } 41 42 bool View::IsFullscreen() const { 43 if (has_interface<PPB_View_1_1>()) { 44 return PP_ToBool(get_interface<PPB_View_1_1>()->IsFullscreen( 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; 51 } 52 53 bool View::IsVisible() const { 54 if (has_interface<PPB_View_1_1>()) 55 return PP_ToBool(get_interface<PPB_View_1_1>()->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; 59 } 60 61 bool View::IsPageVisible() const { 62 if (has_interface<PPB_View_1_1>()) { 63 return PP_ToBool(get_interface<PPB_View_1_1>()->IsPageVisible( 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; 70 } 71 72 Rect View::GetClipRect() const { 73 PP_Rect out; 74 if (has_interface<PPB_View_1_1>()) { 75 if (PP_ToBool(get_interface<PPB_View_1_1>()->GetClipRect(pp_resource(), 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 } 83 return Rect(); 84 } 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 98 } // namespace pp 99