summaryrefslogtreecommitdiffstats
path: root/ppapi/examples
diff options
context:
space:
mode:
authorviettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-18 08:16:22 +0000
committerviettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-18 08:16:22 +0000
commitffadb717d9ab2138fde9dc238ad697449da4d75e (patch)
treeda760106251c583911e476d177c2ed981ecfe211 /ppapi/examples
parent8de46cee7669abb07f6d3e192f5850872187250b (diff)
downloadchromium_src-ffadb717d9ab2138fde9dc238ad697449da4d75e.zip
chromium_src-ffadb717d9ab2138fde9dc238ad697449da4d75e.tar.gz
chromium_src-ffadb717d9ab2138fde9dc238ad697449da4d75e.tar.bz2
Pepper: Add a function to PPB_Flash to check if a rect is topmost.
This is needed for "Flash dialogs". This is dependent on https://bugs.webkit.org/show_bug.cgi?id=78166 . TEST=check the example plugin (under flash_topmost) Review URL: http://codereview.chromium.org/9369003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@122686 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/examples')
-rw-r--r--ppapi/examples/flash_topmost/flash_topmost.cc135
-rw-r--r--ppapi/examples/flash_topmost/flash_topmost.html74
2 files changed, 209 insertions, 0 deletions
diff --git a/ppapi/examples/flash_topmost/flash_topmost.cc b/ppapi/examples/flash_topmost/flash_topmost.cc
new file mode 100644
index 0000000..fe17092
--- /dev/null
+++ b/ppapi/examples/flash_topmost/flash_topmost.cc
@@ -0,0 +1,135 @@
+// Copyright (c) 2012 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/graphics_2d.h"
+#include "ppapi/cpp/image_data.h"
+#include "ppapi/cpp/instance.h"
+#include "ppapi/cpp/logging.h"
+#include "ppapi/cpp/module.h"
+#include "ppapi/cpp/private/flash.h"
+#include "ppapi/cpp/rect.h"
+#include "ppapi/cpp/size.h"
+#include "ppapi/utility/completion_callback_factory.h"
+
+const int32_t kTimerInterval = 200;
+
+class MyInstance : public pp::Instance {
+ public:
+ explicit MyInstance(PP_Instance instance)
+ : pp::Instance(instance),
+ callback_factory_(this),
+ pending_paint_(false),
+ waiting_for_flush_completion_(false) {
+ }
+ virtual ~MyInstance() {
+ }
+
+ virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]) {
+ ScheduleNextTimer();
+ return true;
+ }
+
+ virtual void DidChangeView(const pp::Rect& position, const pp::Rect& clip) {
+ if (position.size() != size_) {
+ size_ = position.size();
+ device_context_ = pp::Graphics2D(this, size_, false);
+ if (!BindGraphics(device_context_))
+ return;
+ }
+
+ Paint();
+ }
+
+ private:
+ void ScheduleNextTimer() {
+ pp::Module::Get()->core()->CallOnMainThread(
+ kTimerInterval,
+ callback_factory_.NewRequiredCallback(&MyInstance::OnTimer),
+ 0);
+ }
+
+ void OnTimer(int32_t) {
+ ScheduleNextTimer();
+ Paint();
+ }
+
+ void DidFlush(int32_t result) {
+ waiting_for_flush_completion_ = false;
+ if (pending_paint_)
+ Paint();
+ }
+
+ void Paint() {
+ if (waiting_for_flush_completion_) {
+ pending_paint_ = true;
+ return;
+ }
+
+ pending_paint_ = false;
+
+ if (size_.IsEmpty())
+ return; // Nothing to do.
+
+ pp::ImageData image = PaintImage(size_);
+ if (!image.is_null()) {
+ device_context_.ReplaceContents(&image);
+ waiting_for_flush_completion_ = true;
+ device_context_.Flush(
+ callback_factory_.NewRequiredCallback(&MyInstance::DidFlush));
+ }
+ }
+
+ pp::ImageData PaintImage(const pp::Size& size) {
+ pp::ImageData image(this, PP_IMAGEDATAFORMAT_BGRA_PREMUL, size, false);
+ if (image.is_null())
+ return image;
+
+ pp::Rect rect(size.width() / 8, size.height() / 4,
+ 3 * size.width() / 4, size.height() / 2);
+ uint32_t fill_color = pp::flash::Flash::IsRectTopmost(this, rect) ?
+ 0xff00ff00 : 0xffff0000;
+
+ for (int y = 0; y < size.height(); y++) {
+ for (int x = 0; x < size.width(); x++)
+ *image.GetAddr32(pp::Point(x, y)) = fill_color;
+ }
+
+ for (int x = rect.x(); x < rect.x() + rect.width(); x++) {
+ *image.GetAddr32(pp::Point(x, rect.y())) = 0xff202020;
+ *image.GetAddr32(pp::Point(x, rect.y() + rect.height() - 1)) = 0xff202020;
+ }
+ for (int y = rect.y(); y < rect.y() + rect.height(); y++) {
+ *image.GetAddr32(pp::Point(rect.x(), y)) = 0xff202020;
+ *image.GetAddr32(pp::Point(rect.x() + rect.width() - 1, y)) = 0xff202020;
+ }
+
+ return image;
+ }
+
+ pp::CompletionCallbackFactory<MyInstance> callback_factory_;
+
+ int32_t timer_interval_;
+
+ // Painting stuff.
+ pp::Size size_;
+ pp::Graphics2D device_context_;
+ bool pending_paint_;
+ bool waiting_for_flush_completion_;
+};
+
+class MyModule : public pp::Module {
+ public:
+ virtual pp::Instance* CreateInstance(PP_Instance instance) {
+ return new MyInstance(instance);
+ }
+};
+
+namespace pp {
+
+// Factory function for your specialization of the Module object.
+Module* CreateModule() {
+ return new MyModule();
+}
+
+} // namespace pp
diff --git a/ppapi/examples/flash_topmost/flash_topmost.html b/ppapi/examples/flash_topmost/flash_topmost.html
new file mode 100644
index 0000000..81ab1c3
--- /dev/null
+++ b/ppapi/examples/flash_topmost/flash_topmost.html
@@ -0,0 +1,74 @@
+<!DOCTYPE html>
+<html>
+ <!--
+ Copyright (c) 2012 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.
+ -->
+<head>
+ <title>Flash Topmost Check Example/Test</title>
+</head>
+
+<style type="text/css">
+#box1 {
+ background-color: #ffff00;
+ line-height: 200px;
+ padding: 0px;
+ position: absolute;
+ text-align: center;
+ width: 200px;
+ height: 200px;
+ z-index: -1;
+}
+#box2 {
+ background-color: #00ffff;
+ line-height: 200px;
+ padding: 0px;
+ position: absolute;
+ text-align: center;
+ width: 200px;
+ height: 200px;
+ z-index: 1;
+}
+</style>
+
+<script type="text/javascript">
+var dragInfo = { lastX:0, lastY:0, target:null };
+
+function onMouseDown(event) {
+ dragInfo.lastX = event.clientX;
+ dragInfo.lastY = event.clientY;
+ dragInfo.target = event.target;
+ document.addEventListener("mousemove", onMouseMove, true);
+ document.addEventListener("mouseup", onMouseUp, true);
+ event.preventDefault();
+}
+
+function onMouseMove(event) {
+ deltaX = event.clientX - dragInfo.lastX;
+ deltaY = event.clientY - dragInfo.lastY;
+ dragInfo.lastX = event.clientX;
+ dragInfo.lastY = event.clientY;
+ baseX = parseInt(dragInfo.target.style.left, 10);
+ baseY = parseInt(dragInfo.target.style.top, 10);
+ dragInfo.target.style.left = (baseX + deltaX) + "px";
+ dragInfo.target.style.top = (baseY + deltaY) + "px";
+ event.preventDefault();
+}
+
+function onMouseUp(event) {
+ document.removeEventListener("mousemove", onMouseMove, true);
+ document.removeEventListener("mouseup", onMouseUp, true);
+ event.preventDefault();
+}
+</script>
+
+<div id="box1" style="left:0px;top:0px;"
+ onmousedown="onMouseDown(event)">Box #1</div>
+<embed id="plugin" type="application/x-ppapi-example-flash-topmost"
+ width="400" height="400"/>
+<div id="box2" style="left:0px;top:100px;"
+ onmousedown="onMouseDown(event)">Box #2</div>
+
+</body>
+</html>