2011-02-15 19:07:24 +01:00
|
|
|
// 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 "webwidget_host.h"
|
2011-03-24 21:36:47 +01:00
|
|
|
#include "cef_thread.h"
|
2011-02-15 19:07:24 +01:00
|
|
|
|
2011-10-12 21:09:15 +02:00
|
|
|
#include "base/bind.h"
|
2011-02-15 19:07:24 +01:00
|
|
|
#include "base/message_loop.h"
|
2011-03-24 21:36:47 +01:00
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebSize.h"
|
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebWidget.h"
|
|
|
|
|
|
|
|
using webkit::npapi::WebPluginGeometry;
|
|
|
|
using WebKit::WebSize;
|
|
|
|
|
2011-02-15 19:07:24 +01:00
|
|
|
|
|
|
|
void WebWidgetHost::ScheduleAnimation() {
|
|
|
|
MessageLoop::current()->PostDelayedTask(FROM_HERE,
|
2011-10-12 21:09:15 +02:00
|
|
|
base::Bind(&WebWidgetHost::ScheduleComposite, weak_factory_.GetWeakPtr()),
|
|
|
|
10);
|
2011-02-15 19:07:24 +01:00
|
|
|
}
|
2011-03-24 21:36:47 +01:00
|
|
|
|
|
|
|
void WebWidgetHost::UpdatePaintRect(const gfx::Rect& rect) {
|
2011-11-14 18:47:21 +01:00
|
|
|
#if defined(OS_WIN) || defined(OS_MACOSX)
|
2011-11-09 21:09:24 +01:00
|
|
|
paint_rgn_.op(rect.x(), rect.y(), rect.right(), rect.bottom(),
|
|
|
|
SkRegion::kUnion_Op);
|
|
|
|
#else
|
|
|
|
// TODO: Update all ports to use regions instead of rectangles.
|
2011-03-24 21:36:47 +01:00
|
|
|
paint_rect_ = paint_rect_.Union(rect);
|
2011-11-09 21:09:24 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebWidgetHost::UpdateRedrawRect(const gfx::Rect& rect) {
|
|
|
|
if (!view_)
|
|
|
|
redraw_rect_ = redraw_rect_.Union(rect);
|
2011-03-24 21:36:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void WebWidgetHost::SetSize(int width, int height) {
|
|
|
|
webwidget_->resize(WebSize(width, height));
|
2011-11-08 17:19:03 +01:00
|
|
|
DidInvalidateRect(gfx::Rect(0, 0, width, height));
|
2011-03-24 21:36:47 +01:00
|
|
|
EnsureTooltip();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebWidgetHost::GetSize(int& width, int& height) {
|
|
|
|
const WebSize& size = webwidget_->size();
|
|
|
|
width = size.width;
|
|
|
|
height = size.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebWidgetHost::AddWindowedPlugin(gfx::PluginWindowHandle handle)
|
|
|
|
{
|
|
|
|
WebPluginGeometry geometry;
|
|
|
|
plugin_map_.insert(std::make_pair(handle, geometry));
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebWidgetHost::RemoveWindowedPlugin(gfx::PluginWindowHandle handle)
|
|
|
|
{
|
|
|
|
PluginMap::iterator it = plugin_map_.find(handle);
|
|
|
|
DCHECK(it != plugin_map_.end());
|
|
|
|
plugin_map_.erase(it);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebWidgetHost::MoveWindowedPlugin(const WebPluginGeometry& move)
|
|
|
|
{
|
|
|
|
PluginMap::iterator it = plugin_map_.find(move.window);
|
|
|
|
DCHECK(it != plugin_map_.end());
|
|
|
|
|
|
|
|
it->second.window = move.window;
|
|
|
|
if (move.rects_valid) {
|
|
|
|
it->second.window_rect = move.window_rect;
|
|
|
|
it->second.clip_rect = move.clip_rect;
|
|
|
|
it->second.cutout_rects = move.cutout_rects;
|
|
|
|
it->second.rects_valid = true;
|
|
|
|
}
|
|
|
|
it->second.visible = move.visible;
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::PluginWindowHandle WebWidgetHost::GetWindowedPluginAt(int x, int y)
|
|
|
|
{
|
|
|
|
if (!plugin_map_.empty()) {
|
|
|
|
PluginMap::const_iterator it = plugin_map_.begin();
|
|
|
|
for(; it != plugin_map_.end(); ++it) {
|
|
|
|
if (it->second.visible && it->second.window_rect.Contains(x, y))
|
|
|
|
return it->second.window;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-24 22:20:52 +02:00
|
|
|
return gfx::kNullPluginWindow;
|
2011-03-24 21:36:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void WebWidgetHost::DoPaint() {
|
|
|
|
// TODO(cef): The below code is cross-platform but the IsIdle() method
|
|
|
|
// currently requires patches to Chromium. Since this code is only executed
|
|
|
|
// on Windows it's been stuck behind an #ifdef for now to avoid having to
|
|
|
|
// patch Chromium code on other platforms.
|
|
|
|
#if defined(OS_WIN)
|
|
|
|
if (MessageLoop::current()->IsIdle()) {
|
2011-11-10 00:13:26 +01:00
|
|
|
has_update_task_ = false;
|
2011-11-14 18:47:21 +01:00
|
|
|
// Paint to the delegate.
|
|
|
|
Paint();
|
2011-03-24 21:36:47 +01:00
|
|
|
} else {
|
|
|
|
// Try again later.
|
2011-10-12 21:09:15 +02:00
|
|
|
CefThread::PostTask(CefThread::UI, FROM_HERE,
|
|
|
|
base::Bind(&WebWidgetHost::DoPaint, weak_factory_.GetWeakPtr()));
|
2011-03-24 21:36:47 +01:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
NOTIMPLEMENTED();
|
|
|
|
#endif
|
|
|
|
}
|