summaryrefslogtreecommitdiffstats
path: root/ppapi/cpp
diff options
context:
space:
mode:
Diffstat (limited to 'ppapi/cpp')
-rw-r--r--ppapi/cpp/instance.cc6
-rw-r--r--ppapi/cpp/instance.h21
-rw-r--r--ppapi/cpp/module.cc6
-rw-r--r--ppapi/cpp/view.cc62
-rw-r--r--ppapi/cpp/view.h114
5 files changed, 203 insertions, 6 deletions
diff --git a/ppapi/cpp/instance.cc b/ppapi/cpp/instance.cc
index 72e4f02..e42adf6 100644
--- a/ppapi/cpp/instance.cc
+++ b/ppapi/cpp/instance.cc
@@ -17,6 +17,7 @@
#include "ppapi/cpp/point.h"
#include "ppapi/cpp/resource.h"
#include "ppapi/cpp/var.h"
+#include "ppapi/cpp/view.h"
namespace pp {
@@ -54,6 +55,11 @@ bool Instance::Init(uint32_t /*argc*/, const char* /*argn*/[],
return true;
}
+void Instance::DidChangeView(const View& view) {
+ // Call the deprecated version for source backwards-compat.
+ DidChangeView(view.GetRect(), view.GetClipRect());
+}
+
void Instance::DidChangeView(const pp::Rect& /*position*/,
const pp::Rect& /*clip*/) {
}
diff --git a/ppapi/cpp/instance.h b/ppapi/cpp/instance.h
index 9a3bfaf..fff23cb2 100644
--- a/ppapi/cpp/instance.h
+++ b/ppapi/cpp/instance.h
@@ -14,6 +14,7 @@
#include "ppapi/c/pp_instance.h"
#include "ppapi/c/pp_resource.h"
#include "ppapi/c/pp_stdint.h"
+#include "ppapi/cpp/view.h"
struct PP_InputEvent;
@@ -90,9 +91,23 @@ class Instance {
/// @{
/// @name PPP_Instance methods for the module to override:
- /// DidChangeView() is called when the position, the size, or the clip
- /// rectangle of the element in the browser that corresponds to this
- /// instance has changed.
+ /// DidChangeView() is called when the view information for the Instance
+ /// has changed. See the <code>View</code> object for information.
+ ///
+ /// Most implementations will want to check if the size and user visibility
+ /// changed, and either resize themselves or start/stop generating updates.
+ ///
+ /// You should not call the default implementation. For
+ /// backwards-compatibility, it will call the deprecated version of
+ /// DidChangeView below.
+ virtual void DidChangeView(const View& view);
+
+ /// Deprecated backwards-compatible version of <code>DidChangeView()</code>.
+ /// New code should derive from the version that takes a
+ /// <code>ViewChanged</code> object rather than this version. This function
+ /// is called by the default implementation of the newer
+ /// <code>DidChangeView</code> function for source compatibility with older
+ /// code.
///
/// A typical implementation will check the size of the <code>position</code>
/// argument and reallocate the graphics context when a different size is
diff --git a/ppapi/cpp/module.cc b/ppapi/cpp/module.cc
index b727e46..fd130ad 100644
--- a/ppapi/cpp/module.cc
+++ b/ppapi/cpp/module.cc
@@ -36,6 +36,7 @@
#include "ppapi/cpp/resource.h"
#include "ppapi/cpp/url_loader.h"
#include "ppapi/cpp/var.h"
+#include "ppapi/cpp/view.h"
namespace pp {
@@ -89,15 +90,14 @@ void Instance_DidDestroy(PP_Instance instance) {
}
void Instance_DidChangeView(PP_Instance pp_instance,
- const PP_Rect* position,
- const PP_Rect* clip) {
+ PP_Resource view_resource) {
Module* module_singleton = Module::Get();
if (!module_singleton)
return;
Instance* instance = module_singleton->InstanceForPPInstance(pp_instance);
if (!instance)
return;
- instance->DidChangeView(*position, *clip);
+ instance->DidChangeView(View(view_resource));
}
void Instance_DidChangeFocus(PP_Instance pp_instance, PP_Bool has_focus) {
diff --git a/ppapi/cpp/view.cc b/ppapi/cpp/view.cc
new file mode 100644
index 0000000..f81bc1a
--- /dev/null
+++ b/ppapi/cpp/view.cc
@@ -0,0 +1,62 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ppapi/cpp/view.h"
+
+#include "ppapi/c/ppb_view.h"
+#include "ppapi/cpp/module_impl.h"
+
+namespace pp {
+
+namespace {
+
+template <> const char* interface_name<PPB_View>() {
+ return PPB_VIEW_INTERFACE;
+}
+
+} // namespace
+
+View::View() : Resource() {
+}
+
+View::View(PP_Resource view_resource) : Resource(view_resource) {
+}
+
+Rect View::GetRect() const {
+ if (!has_interface<PPB_View>())
+ return Rect();
+ PP_Rect out;
+ if (PP_ToBool(get_interface<PPB_View>()->GetRect(pp_resource(), &out)))
+ return Rect(out);
+ return Rect();
+}
+
+bool View::IsFullscreen() const {
+ if (!has_interface<PPB_View>())
+ return false;
+ return PP_ToBool(get_interface<PPB_View>()->IsFullscreen(pp_resource()));
+}
+
+bool View::IsVisible() const {
+ if (!has_interface<PPB_View>())
+ return false;
+ return PP_ToBool(get_interface<PPB_View>()->IsVisible(pp_resource()));
+}
+
+bool View::IsPageVisible() const {
+ if (!has_interface<PPB_View>())
+ return true;
+ return PP_ToBool(get_interface<PPB_View>()->IsPageVisible(pp_resource()));
+}
+
+Rect View::GetClipRect() const {
+ if (!has_interface<PPB_View>())
+ return Rect();
+ PP_Rect out;
+ if (PP_ToBool(get_interface<PPB_View>()->GetClipRect(pp_resource(), &out)))
+ return Rect(out);
+ return Rect();
+}
+
+} // namespace pp
diff --git a/ppapi/cpp/view.h b/ppapi/cpp/view.h
new file mode 100644
index 0000000..ee925b0
--- /dev/null
+++ b/ppapi/cpp/view.h
@@ -0,0 +1,114 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef PPAPI_CPP_VIEW_H_
+#define PPAPI_CPP_VIEW_H_
+
+#include "ppapi/cpp/resource.h"
+#include "ppapi/cpp/rect.h"
+#include "ppapi/cpp/size.h"
+
+namespace pp {
+
+class View : public Resource {
+ public:
+ /// Default constructor for creating an is_null() <code>View</code> object.
+ View();
+
+ /// Creates a View resource, taking and holding an additional reference to
+ /// the given resource handle.
+ View(PP_Resource view_resource);
+
+ /// <code>GetRect()</code> returns the rectangle of the instance
+ /// associated with the view changed notification relative to the upper left
+ /// of the browser viewport. This position changes when the page is scrolled.
+ ///
+ /// The returned rectangle may not be inside the visible portion of the
+ /// viewport if the instance is scrolled off the page. Therefore, the
+ /// position may be negative or larger than the size of the page. The size
+ /// will always reflect the size of the plugin were it to be scrolled
+ /// entirely into view.
+ ///
+ /// In general, most plugins will not need to worry about the position of the
+ /// instance in the viewport, and only need to use the size.
+ ///
+ /// @return The rectangle of the instance. The default return value for
+ /// an invalid View is the empty rectangle.
+ Rect GetRect() const;
+
+ /// <code>IsFullscreen()</code> returns whether the instance is currently
+ /// displaying in fullscreen mode.
+ ///
+ /// @return <code>true</code> if the instance is in full screen mode,
+ /// or <code>false</code> if it's not or the resource is invalid.
+ bool IsFullscreen() const;
+
+ /// <code>IsVisible()</code> returns true if the instance is plausibly
+ /// visible to the user. You should use this flag to throttle or stop updates
+ /// for invisible plugins.
+ ///
+ /// Thie measure incorporates both whether the instance is scrolled into
+ /// view (whether the clip rect is nonempty) and whether the page is
+ /// plausibly visible to the user (<code>IsPageVisible()</code>).
+ ///
+ /// @return <code>true</code> if the instance is plausibly visible to the
+ /// user, <code>false</code> if it is definitely not visible.
+ bool IsVisible() const;
+
+ /// <code>IsPageVisible()</code> determines if the page that contains the
+ /// instance is visible. The most common cause of invisible pages is that
+ /// the page is in a background tab in the browser.
+ ///
+ /// Most applications should use <code>IsVisible()</code> rather than
+ /// this function since the instance could be scrolled off of a visible
+ /// page, and this function will still return true. However, depending on
+ /// how your plugin interacts with the page, there may be certain updates
+ /// that you may want to perform when the page is visible even if your
+ /// specific instance isn't.
+ ///
+ /// @return <code>true</code> if the instance is plausibly visible to the
+ /// user, <code>false</code> if it is definitely not visible.
+ bool IsPageVisible() const;
+
+ /// <code>GetClip()</code> returns the clip rectangle relative to the upper
+ /// left corner of the instance. This rectangle indicates which parts of the
+ /// instance are scrolled into view.
+ ///
+ /// If the instance is scrolled off the view, the return value will be
+ /// (0, 0, 0, 0). this state. This clip rect does <i>not</i> take into account
+ /// page visibility. This means if the instance is scrolled into view but the
+ /// page itself is in an invisible tab, the return rect will contain the
+ /// visible rect assuming the page was visible. See
+ /// <code>IsPageVisible()</code> and <code>IsVisible()</code> if you want
+ /// to handle this case.
+ ///
+ /// Most applications will not need to worry about the clip. The recommended
+ /// behavior is to do full updates if the instance is visible as determined by
+ /// <code>IsUserVisible()</code> and do no updates if not.
+ ///
+ /// However, if the cost for computing pixels is very high for your
+ /// application or the pages you're targeting frequently have very large
+ /// instances with only portions visible, you may wish to optimize further.
+ /// In this case, the clip rect will tell you which parts of the plugin to
+ /// update.
+ ///
+ /// Note that painting of the page and sending of view changed updates
+ /// happens asynchronously. This means when the user scrolls, for example,
+ /// it is likely that the previous backing store of the instance will be used
+ /// for the first paint, and will be updated later when your application
+ /// generates new content. This may cause flickering at the boundaries when
+ /// scrolling. If you do choose to do partial updates, you may want to think
+ /// about what color the invisible portions of your backing store contain
+ /// (be it transparent or some background color) or to paint a certain
+ /// region outside the clip to reduce the visual distraction when this
+ /// happens.
+ ///
+ /// @return The rectangle representing the visible part of the instance.
+ /// If the resource is invalid, the empty rect is returned.
+ Rect GetClipRect() const;
+};
+
+} // namespace pp
+
+#endif // PPAPI_CPP_VIEW_H_