• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/shared_impl/ppb_view_shared.h"
6 
7 namespace {
8 
IsRectNonempty(const PP_Rect & rect)9 bool IsRectNonempty(const PP_Rect& rect) {
10   return rect.size.width > 0 && rect.size.height > 0;
11 }
12 
13 }  // namespace
14 
15 namespace ppapi {
16 
ViewData()17 ViewData::ViewData() {
18   // Assume POD.
19   memset(this, 0, sizeof(ViewData));
20 
21   device_scale = 1.0f;
22   css_scale = 1.0f;
23 }
24 
~ViewData()25 ViewData::~ViewData() {}
26 
Equals(const ViewData & other) const27 bool ViewData::Equals(const ViewData& other) const {
28   return rect.point.x == other.rect.point.x &&
29          rect.point.y == other.rect.point.y &&
30          rect.size.width == other.rect.size.width &&
31          rect.size.height == other.rect.size.height &&
32          is_fullscreen == other.is_fullscreen &&
33          is_page_visible == other.is_page_visible &&
34          clip_rect.point.x == other.clip_rect.point.x &&
35          clip_rect.point.y == other.clip_rect.point.y &&
36          clip_rect.size.width == other.clip_rect.size.width &&
37          clip_rect.size.height == other.clip_rect.size.height &&
38          device_scale == other.device_scale && css_scale == other.css_scale &&
39          scroll_offset.x == other.scroll_offset.x &&
40          scroll_offset.y == other.scroll_offset.y;
41 }
42 
PPB_View_Shared(ResourceObjectType type,PP_Instance instance,const ViewData & data)43 PPB_View_Shared::PPB_View_Shared(ResourceObjectType type,
44                                  PP_Instance instance,
45                                  const ViewData& data)
46     : Resource(type, instance), data_(data) {}
47 
~PPB_View_Shared()48 PPB_View_Shared::~PPB_View_Shared() {}
49 
AsPPB_View_API()50 thunk::PPB_View_API* PPB_View_Shared::AsPPB_View_API() { return this; }
51 
GetData() const52 const ViewData& PPB_View_Shared::GetData() const { return data_; }
53 
GetRect(PP_Rect * viewport) const54 PP_Bool PPB_View_Shared::GetRect(PP_Rect* viewport) const {
55   if (!viewport)
56     return PP_FALSE;
57   *viewport = data_.rect;
58   return PP_TRUE;
59 }
60 
IsFullscreen() const61 PP_Bool PPB_View_Shared::IsFullscreen() const {
62   return PP_FromBool(data_.is_fullscreen);
63 }
64 
IsVisible() const65 PP_Bool PPB_View_Shared::IsVisible() const {
66   return PP_FromBool(data_.is_page_visible && IsRectNonempty(data_.clip_rect));
67 }
68 
IsPageVisible() const69 PP_Bool PPB_View_Shared::IsPageVisible() const {
70   return PP_FromBool(data_.is_page_visible);
71 }
72 
GetClipRect(PP_Rect * clip) const73 PP_Bool PPB_View_Shared::GetClipRect(PP_Rect* clip) const {
74   if (!clip)
75     return PP_FALSE;
76   *clip = data_.clip_rect;
77   return PP_TRUE;
78 }
79 
GetDeviceScale() const80 float PPB_View_Shared::GetDeviceScale() const { return data_.device_scale; }
81 
GetCSSScale() const82 float PPB_View_Shared::GetCSSScale() const { return data_.css_scale; }
83 
GetScrollOffset(PP_Point * scroll_offset) const84 PP_Bool PPB_View_Shared::GetScrollOffset(PP_Point* scroll_offset) const {
85   if (!scroll_offset)
86     return PP_FALSE;
87   *scroll_offset = data_.scroll_offset;
88   return PP_TRUE;
89 }
90 
91 }  // namespace ppapi
92