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 #ifndef PPAPI_CPP_VIEW_H_ | 5 #ifndef PPAPI_CPP_VIEW_H_ |
6 #define PPAPI_CPP_VIEW_H_ | 6 #define PPAPI_CPP_VIEW_H_ |
7 | 7 |
8 #include "ppapi/cpp/resource.h" | 8 #include "ppapi/cpp/resource.h" |
9 #include "ppapi/cpp/rect.h" | 9 #include "ppapi/cpp/rect.h" |
10 #include "ppapi/cpp/size.h" | 10 #include "ppapi/cpp/size.h" |
11 | 11 |
12 /// @file | 12 /// @file |
13 /// This file defines the API for getting the state of a the view for an | 13 /// This file defines the API for getting the state of a the view for an |
14 /// instance. | 14 /// instance. |
15 | 15 |
16 namespace pp { | 16 namespace pp { |
17 | 17 |
18 /// This class represents the state of the view for an instance and contains | 18 /// This class represents the state of the view for an instance and contains |
19 /// functions for retrieving the current state of that view. | 19 /// functions for retrieving the current state of that view. |
20 class View : public Resource { | 20 class View : public Resource { |
21 public: | 21 public: |
22 /// Default constructor for creating an is_null() <code>View</code> object. | 22 /// Default constructor for creating an is_null() <code>View</code> object. |
23 View(); | 23 View(); |
24 | 24 |
25 /// Creates a View resource, taking and holding an additional reference to | 25 /// Creates a View resource, taking and holding an additional reference to |
26 /// the given resource handle. | 26 /// the given resource handle. |
27 View(PP_Resource view_resource); | 27 View(PP_Resource view_resource); |
28 | 28 |
29 /// <code>GetRect()</code> returns the rectangle of the instance | 29 /// GetRect() retrieves the rectangle of the module instance associated |
30 /// associated with the view changed notification relative to the upper left | 30 /// with a view changed notification relative to the upper-left of the browser |
31 /// of the browser viewport. This position changes when the page is scrolled. | 31 /// viewport. This position changes when the page is scrolled. |
32 /// | 32 /// |
33 /// The returned rectangle may not be inside the visible portion of the | 33 /// The returned rectangle may not be inside the visible portion of the |
34 /// viewport if the instance is scrolled off the page. Therefore, the | 34 /// viewport if the module instance is scrolled off the page. Therefore, the |
35 /// position may be negative or larger than the size of the page. The size | 35 /// position may be negative or larger than the size of the page. The size |
36 /// will always reflect the size of the plugin were it to be scrolled | 36 /// will always reflect the size of the module were it to be scrolled |
37 /// entirely into view. | 37 /// entirely into view. |
38 /// | 38 /// |
39 /// In general, most plugins will not need to worry about the position of the | 39 /// In general, most modules will not need to worry about the position of the |
40 /// instance in the viewport, and only need to use the size. | 40 ///module instance in the viewport, and only need to use the size. |
41 /// | 41 /// |
42 /// @return The rectangle of the instance. The default return value for | 42 /// @return The rectangle of the instance. The default return value for |
43 /// an invalid View is the empty rectangle. | 43 /// an invalid View is the empty rectangle. |
44 Rect GetRect() const; | 44 Rect GetRect() const; |
45 | 45 |
46 /// <code>IsFullscreen()</code> returns whether the instance is currently | 46 /// IsFullscreen() returns whether the instance is currently |
47 /// displaying in fullscreen mode. | 47 /// displaying in fullscreen mode. |
48 /// | 48 /// |
49 /// @return <code>true</code> if the instance is in full screen mode, | 49 /// @return <code>true</code> if the instance is in full screen mode, |
50 /// or <code>false</code> if it's not or the resource is invalid. | 50 /// or <code>false</code> if it's not or the resource is invalid. |
51 bool IsFullscreen() const; | 51 bool IsFullscreen() const; |
52 | 52 |
53 /// <code>IsVisible()</code> returns true if the instance is plausibly | 53 /// IsVisible() determines whether the module instance might be visible to |
54 /// visible to the user. You should use this flag to throttle or stop updates | 54 /// the user. For example, the Chrome window could be minimized or another |
55 /// for invisible plugins. | 55 /// window could be over it. In both of these cases, the module instance |
| 56 /// would not be visible to the user, but IsVisible() will return true. |
56 /// | 57 /// |
57 /// Thie measure incorporates both whether the instance is scrolled into | 58 /// Use the result to speed up or stop updates for invisible module |
58 /// view (whether the clip rect is nonempty) and whether the page is | 59 /// instances. |
59 /// plausibly visible to the user (<code>IsPageVisible()</code>). | |
60 /// | 60 /// |
61 /// @return <code>true</code> if the instance is plausibly visible to the | 61 /// This function performs the duties of GetRect() (determining whether the |
| 62 /// module instance is scrolled into view and the clip rectangle is nonempty) |
| 63 /// and IsPageVisible() (whether the page is visible to the user). |
| 64 /// |
| 65 /// @return <code>true</code> if the instance might be visible to the |
62 /// user, <code>false</code> if it is definitely not visible. | 66 /// user, <code>false</code> if it is definitely not visible. |
63 bool IsVisible() const; | 67 bool IsVisible() const; |
64 | 68 |
65 /// <code>IsPageVisible()</code> determines if the page that contains the | 69 /// IsPageVisible() determines if the page that contains the module instance |
66 /// instance is visible. The most common cause of invisible pages is that | 70 /// is visible. The most common cause of invisible pages is that |
67 /// the page is in a background tab in the browser. | 71 /// the page is in a background tab in the browser. |
68 /// | 72 /// |
69 /// Most applications should use <code>IsVisible()</code> rather than | 73 /// Most applications should use IsVisible() instead of this function since |
70 /// this function since the instance could be scrolled off of a visible | 74 /// the module instance could be scrolled off of a visible page, and this |
71 /// page, and this function will still return true. However, depending on | 75 /// function will still return true. However, depending on how your module |
72 /// how your plugin interacts with the page, there may be certain updates | 76 /// interacts with the page, there may be certain updates that you may want |
73 /// that you may want to perform when the page is visible even if your | 77 /// to perform when the page is visible even if your specific module instance |
74 /// specific instance isn't. | 78 /// is not visible. |
75 /// | 79 /// |
76 /// @return <code>true</code> if the instance is plausibly visible to the | 80 /// @return <code>true</code> if the instance might be visible to the |
77 /// user, <code>false</code> if it is definitely not visible. | 81 /// user, <code>false</code> if it is definitely not visible. |
78 bool IsPageVisible() const; | 82 bool IsPageVisible() const; |
79 | 83 |
80 /// <code>GetClip()</code> returns the clip rectangle relative to the upper | 84 /// GetClipRect() returns the clip rectangle relative to the upper-left corner |
81 /// left corner of the instance. This rectangle indicates which parts of the | 85 /// of the module instance. This rectangle indicates the portions of the |
82 /// instance are scrolled into view. | 86 /// module instance that are scrolled into view. |
83 /// | 87 /// |
84 /// If the instance is scrolled off the view, the return value will be | 88 /// If the module instance is scrolled off the view, the return value will be |
85 /// (0, 0, 0, 0). this state. This clip rect does <i>not</i> take into account | 89 /// (0, 0, 0, 0). This clip rectangle does <i>not</i> take into account page |
86 /// page visibility. This means if the instance is scrolled into view but the | 90 /// visibility. Therefore, if the module instance is scrolled into view, but |
87 /// page itself is in an invisible tab, the return rect will contain the | 91 /// the page itself is on a tab that is not visible, the return rectangle will |
88 /// visible rect assuming the page was visible. See | 92 /// contain the visible rectangle as though the page were visible. Refer to |
89 /// <code>IsPageVisible()</code> and <code>IsVisible()</code> if you want | 93 /// IsPageVisible() and IsVisible() if you want to account for page |
90 /// to handle this case. | 94 /// visibility. |
91 /// | 95 /// |
92 /// Most applications will not need to worry about the clip. The recommended | 96 /// Most applications will not need to worry about the clip rectangle. The |
93 /// behavior is to do full updates if the instance is visible as determined by | 97 /// recommended behavior is to do full updates if the module instance is |
94 /// <code>IsUserVisible()</code> and do no updates if not. | 98 /// visible, as determined by IsVisible(), and do no updates if it is not |
| 99 /// visible. |
95 /// | 100 /// |
96 /// However, if the cost for computing pixels is very high for your | 101 /// However, if the cost for computing pixels is very high for your |
97 /// application or the pages you're targeting frequently have very large | 102 /// application, or the pages you're targeting frequently have very large |
98 /// instances with only portions visible, you may wish to optimize further. | 103 /// module instances with small visible portions, you may wish to optimize |
99 /// In this case, the clip rect will tell you which parts of the plugin to | 104 /// further. In this case, the clip rectangle will tell you which parts of |
100 /// update. | 105 /// the module to update. |
101 /// | 106 /// |
102 /// Note that painting of the page and sending of view changed updates | 107 /// Note that painting of the page and sending of view changed updates |
103 /// happens asynchronously. This means when the user scrolls, for example, | 108 /// happens asynchronously. This means when the user scrolls, for example, |
104 /// it is likely that the previous backing store of the instance will be used | 109 /// it is likely that the previous backing store of the module instance will |
105 /// for the first paint, and will be updated later when your application | 110 /// be used for the first paint, and will be updated later when your |
106 /// generates new content. This may cause flickering at the boundaries when | 111 /// application generates new content with the new clip. This may cause |
107 /// scrolling. If you do choose to do partial updates, you may want to think | 112 /// flickering at the boundaries when scrolling. If you do choose to do |
108 /// about what color the invisible portions of your backing store contain | 113 /// partial updates, you may want to think about what color the invisible |
109 /// (be it transparent or some background color) or to paint a certain | 114 /// portions of your backing store contain (be it transparent or some |
110 /// region outside the clip to reduce the visual distraction when this | 115 /// background color) or to paint a certain region outside the clip to reduce |
111 /// happens. | 116 /// the visual distraction when this happens. |
112 /// | 117 /// |
113 /// @return The rectangle representing the visible part of the instance. | 118 /// @return The rectangle representing the visible part of the module |
114 /// If the resource is invalid, the empty rect is returned. | 119 /// instance. If the resource is invalid, the empty rectangle is returned. |
115 Rect GetClipRect() const; | 120 Rect GetClipRect() const; |
116 }; | 121 }; |
117 | 122 |
118 } // namespace pp | 123 } // namespace pp |
119 | 124 |
120 #endif // PPAPI_CPP_VIEW_H_ | 125 #endif // PPAPI_CPP_VIEW_H_ |
OLD | NEW |