2010-10-03 23:04:50 +02:00
|
|
|
// Copyright (c) 2006-2008 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.
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
#ifndef CEF_LIBCEF_WEBWIDGET_HOST_H_
|
|
|
|
#define CEF_LIBCEF_WEBWIDGET_HOST_H_
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <vector>
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2011-05-20 22:52:47 +02:00
|
|
|
#include "include/internal/cef_string.h"
|
|
|
|
#include "include/internal/cef_types.h"
|
2011-11-09 21:09:24 +01:00
|
|
|
#include "include/internal/cef_types_wrappers.h"
|
2012-01-10 00:46:23 +01:00
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
#include "base/basictypes.h"
|
2011-09-23 02:16:03 +02:00
|
|
|
#include "base/memory/scoped_ptr.h"
|
2011-12-16 13:24:09 +01:00
|
|
|
#include "base/time.h"
|
2012-08-13 18:27:44 +02:00
|
|
|
#include "base/timer.h"
|
2010-10-03 23:04:50 +02:00
|
|
|
#include "skia/ext/platform_canvas.h"
|
2011-02-15 19:07:24 +01:00
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
|
2011-12-16 15:51:10 +01:00
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h"
|
2011-06-14 18:18:43 +02:00
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebTextInputType.h"
|
2011-11-09 21:09:24 +01:00
|
|
|
#include "third_party/skia/include/core/SkRegion.h"
|
2011-02-15 19:07:24 +01:00
|
|
|
#include "ui/gfx/native_widget_types.h"
|
|
|
|
#include "ui/gfx/rect.h"
|
2011-03-24 21:36:47 +01:00
|
|
|
#include "webkit/plugins/npapi/webplugin.h"
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2011-06-14 18:18:43 +02:00
|
|
|
#if defined(OS_WIN)
|
|
|
|
#include "ui/base/win/ime_input.h"
|
|
|
|
#endif
|
|
|
|
|
2012-04-11 21:37:06 +02:00
|
|
|
#if defined(TOOLKIT_GTK)
|
2012-01-10 00:46:23 +01:00
|
|
|
#include <gtk/gtk.h> // NOLINT(build/include_order)
|
2011-11-04 19:19:14 +01:00
|
|
|
#endif
|
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
namespace gfx {
|
2010-11-15 16:39:56 +01:00
|
|
|
class Rect;
|
2010-10-03 23:04:50 +02:00
|
|
|
class Size;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace WebKit {
|
|
|
|
class WebWidget;
|
|
|
|
class WebWidgetClient;
|
|
|
|
class WebKeyboardEvent;
|
|
|
|
struct WebScreenInfo;
|
|
|
|
}
|
|
|
|
|
2010-10-09 20:23:06 +02:00
|
|
|
#if defined(OS_MACOSX)
|
|
|
|
#ifdef __OBJC__
|
|
|
|
@class NSEvent;
|
|
|
|
#else
|
|
|
|
class NSEvent;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// This class is a simple NativeView-based host for a WebWidget
|
2010-10-03 23:04:50 +02:00
|
|
|
class WebWidgetHost {
|
|
|
|
public:
|
2011-03-24 21:36:47 +01:00
|
|
|
class PaintDelegate {
|
|
|
|
public:
|
2012-01-10 00:46:23 +01:00
|
|
|
virtual ~PaintDelegate() {}
|
2011-11-09 21:09:24 +01:00
|
|
|
virtual void Paint(bool popup, const std::vector<CefRect>& dirtyRects,
|
2011-03-24 21:36:47 +01:00
|
|
|
const void* buffer) =0;
|
|
|
|
};
|
|
|
|
|
2010-10-09 20:23:06 +02:00
|
|
|
// The new instance is deleted once the associated NativeView is destroyed.
|
2010-10-03 23:04:50 +02:00
|
|
|
// The newly created window should be resized after it is created, using the
|
|
|
|
// MoveWindow (or equivalent) function.
|
|
|
|
static WebWidgetHost* Create(gfx::NativeView parent_view,
|
2011-03-24 21:36:47 +01:00
|
|
|
WebKit::WebWidgetClient* client,
|
|
|
|
PaintDelegate* paint_delegate);
|
|
|
|
|
|
|
|
virtual ~WebWidgetHost();
|
2010-10-03 23:04:50 +02:00
|
|
|
|
|
|
|
gfx::NativeView view_handle() const { return view_; }
|
|
|
|
WebKit::WebWidget* webwidget() const { return webwidget_; }
|
|
|
|
|
2012-08-21 21:48:29 +02:00
|
|
|
void InvalidateRect(const gfx::Rect& rect);
|
|
|
|
|
|
|
|
void ScrollRect(int dx, int dy, const gfx::Rect& clip_rect);
|
2011-12-16 13:24:09 +01:00
|
|
|
|
|
|
|
// Called for accelerated content like WebGL.
|
2010-10-03 23:04:50 +02:00
|
|
|
void ScheduleComposite();
|
2011-12-16 13:24:09 +01:00
|
|
|
|
|
|
|
// Called for requestAnimationFrame animations.
|
2011-02-15 19:07:24 +01:00
|
|
|
void ScheduleAnimation();
|
2011-12-16 13:24:09 +01:00
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
#if defined(OS_WIN)
|
|
|
|
void SetCursor(HCURSOR cursor);
|
|
|
|
#endif
|
|
|
|
|
2011-11-14 18:47:21 +01:00
|
|
|
#if defined(OS_MACOSX)
|
|
|
|
void Paint(SkRegion& update_rgn);
|
|
|
|
#else
|
|
|
|
void Paint();
|
|
|
|
#endif
|
2011-03-24 21:36:47 +01:00
|
|
|
|
|
|
|
bool GetImage(int width, int height, void* buffer);
|
|
|
|
|
|
|
|
void SetSize(int width, int height);
|
|
|
|
void GetSize(int& width, int& height);
|
2010-10-03 23:04:50 +02:00
|
|
|
|
|
|
|
skia::PlatformCanvas* canvas() const { return canvas_.get(); }
|
|
|
|
|
|
|
|
WebKit::WebScreenInfo GetScreenInfo();
|
|
|
|
|
|
|
|
WebKit::WebKeyboardEvent GetLastKeyEvent() const { return last_key_event_; }
|
2012-09-26 18:42:42 +02:00
|
|
|
|
|
|
|
void SetLastKeyEvent(WebKit::WebKeyboardEvent keyEvent)
|
|
|
|
{ last_key_event_ = keyEvent; }
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2010-11-22 18:49:46 +01:00
|
|
|
void SetTooltipText(const CefString& tooltip_text);
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2012-05-16 18:56:38 +02:00
|
|
|
void SendKeyEvent(cef_key_type_t type, const cef_key_info_t& keyInfo,
|
|
|
|
int modifiers);
|
2011-03-24 21:36:47 +01:00
|
|
|
void SendMouseClickEvent(int x, int y, cef_mouse_button_type_t type,
|
|
|
|
bool mouseUp, int clickCount);
|
|
|
|
void SendMouseMoveEvent(int x, int y, bool mouseLeave);
|
2012-05-16 18:56:38 +02:00
|
|
|
void SendMouseWheelEvent(int x, int y, int deltaX, int deltaY);
|
2011-03-24 21:36:47 +01:00
|
|
|
void SendFocusEvent(bool setFocus);
|
|
|
|
void SendCaptureLostEvent();
|
|
|
|
|
|
|
|
// Manage windowed plugins when window rendering is disabled.
|
|
|
|
bool HasWindowedPlugins() { return !plugin_map_.empty(); }
|
|
|
|
void AddWindowedPlugin(gfx::PluginWindowHandle handle);
|
|
|
|
void RemoveWindowedPlugin(gfx::PluginWindowHandle handle);
|
|
|
|
void MoveWindowedPlugin(const webkit::npapi::WebPluginGeometry& geometry);
|
|
|
|
gfx::PluginWindowHandle GetWindowedPluginAt(int x, int y);
|
|
|
|
|
2012-08-15 01:33:57 +02:00
|
|
|
void SetFrameRate(int frames_per_second);
|
|
|
|
|
2012-08-21 21:48:29 +02:00
|
|
|
virtual bool IsTransparent() { return false; }
|
|
|
|
|
2011-02-01 16:37:47 +01:00
|
|
|
void set_popup(bool popup) { popup_ = popup; }
|
|
|
|
bool popup() { return popup_; }
|
|
|
|
|
2011-03-24 21:36:47 +01:00
|
|
|
PaintDelegate* paint_delegate() { return paint_delegate_; }
|
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
protected:
|
|
|
|
WebWidgetHost();
|
|
|
|
|
2012-08-21 21:48:29 +02:00
|
|
|
// Update the region that will be painted to the canvas by WebKit the next
|
|
|
|
// time that Paint() is called.
|
|
|
|
void UpdatePaintRect(const gfx::Rect& rect);
|
|
|
|
|
|
|
|
void PaintRect(const gfx::Rect& rect);
|
|
|
|
|
|
|
|
// Trigger the OS to invalidate/repaint the window.
|
|
|
|
void InvalidateWindow();
|
|
|
|
void InvalidateWindowRect(const gfx::Rect& rect);
|
2012-08-15 01:33:57 +02:00
|
|
|
|
2012-08-21 21:48:29 +02:00
|
|
|
// When window rendering is enabled this method invalidates the client area to
|
|
|
|
// trigger repaint via the OS. When window rendering is disabled this method
|
|
|
|
// is used to generate CefRenderHandler::OnPaint() calls.
|
|
|
|
void ScheduleTimer();
|
|
|
|
void DoTimer();
|
2012-08-13 18:27:44 +02:00
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
#if defined(OS_WIN)
|
|
|
|
// Per-class wndproc. Returns true if the event should be swallowed.
|
|
|
|
virtual bool WndProc(UINT message, WPARAM wparam, LPARAM lparam);
|
|
|
|
|
2011-02-28 01:33:11 +01:00
|
|
|
virtual void MouseEvent(UINT message, WPARAM wparam, LPARAM lparam);
|
2010-10-03 23:04:50 +02:00
|
|
|
void WheelEvent(WPARAM wparam, LPARAM lparam);
|
2011-11-04 19:19:14 +01:00
|
|
|
virtual void KeyEvent(UINT message, WPARAM wparam, LPARAM lparam);
|
2010-10-03 23:04:50 +02:00
|
|
|
void CaptureLostEvent();
|
|
|
|
void SetFocus(bool enable);
|
|
|
|
void OnNotify(WPARAM wparam, NMHDR* header);
|
|
|
|
|
|
|
|
static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
|
2011-11-08 17:19:03 +01:00
|
|
|
LRESULT OnImeSetContext(UINT message, WPARAM wparam, LPARAM lparam,
|
|
|
|
BOOL& handled);
|
|
|
|
LRESULT OnImeStartComposition(UINT message, WPARAM wparam, LPARAM lparam,
|
|
|
|
BOOL& handled);
|
|
|
|
LRESULT OnImeComposition(UINT message, WPARAM wparam, LPARAM lparam,
|
|
|
|
BOOL& handled);
|
|
|
|
LRESULT OnImeEndComposition(UINT message, WPARAM wparam, LPARAM lparam,
|
|
|
|
BOOL& handled);
|
2011-06-14 18:18:43 +02:00
|
|
|
void OnInputLangChange(DWORD character_set, HKL input_language_id);
|
2012-08-13 18:27:44 +02:00
|
|
|
void UpdateImeInputState();
|
|
|
|
void ToggleImeTimer();
|
2010-10-03 23:04:50 +02:00
|
|
|
#elif defined(OS_MACOSX)
|
|
|
|
// These need to be called from a non-subclass, so they need to be public.
|
|
|
|
public:
|
2012-01-10 00:46:23 +01:00
|
|
|
virtual void MouseEvent(NSEvent* event);
|
|
|
|
void WheelEvent(NSEvent* event);
|
|
|
|
virtual void KeyEvent(NSEvent* event);
|
2011-08-02 18:50:06 +02:00
|
|
|
virtual void SetFocus(bool enable);
|
2012-01-10 00:46:23 +01:00
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
protected:
|
2012-04-11 21:37:06 +02:00
|
|
|
#elif defined(TOOLKIT_GTK)
|
2012-01-10 00:46:23 +01:00
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
public:
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
// This is needed on Linux because the GtkWidget creation is the same between
|
|
|
|
// both web view hosts and web widget hosts. The Windows code manages this by
|
|
|
|
// reusing the WndProc function (static, above). However, GTK doesn't use a
|
|
|
|
// single big callback function like that so we have a static function that
|
|
|
|
// sets up a GtkWidget correctly.
|
|
|
|
// parent: a GtkBox to pack the new widget at the end of
|
|
|
|
// host: a pointer to a WebWidgetHost (or subclass thereof)
|
|
|
|
// ---------------------------------------------------------------------------
|
2010-10-09 20:23:06 +02:00
|
|
|
static gfx::NativeView CreateWidget(gfx::NativeView parent_view,
|
2010-10-03 23:04:50 +02:00
|
|
|
WebWidgetHost* host);
|
2011-11-04 19:19:14 +01:00
|
|
|
virtual void KeyEvent(GdkEventKey* event);
|
2010-10-03 23:04:50 +02:00
|
|
|
#endif
|
|
|
|
|
2010-10-09 20:23:06 +02:00
|
|
|
#if defined(OS_WIN)
|
2010-10-03 23:04:50 +02:00
|
|
|
void TrackMouseLeave(bool enable);
|
2010-10-09 20:23:06 +02:00
|
|
|
#endif
|
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
void set_painting(bool value) {
|
|
|
|
painting_ = value;
|
|
|
|
}
|
2011-02-01 16:37:47 +01:00
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
void EnsureTooltip();
|
|
|
|
void ResetTooltip();
|
|
|
|
|
|
|
|
gfx::NativeView view_;
|
2011-03-24 21:36:47 +01:00
|
|
|
|
|
|
|
// The paint delegate is used instead of the view when window rendering is
|
|
|
|
// disabled.
|
|
|
|
PaintDelegate* paint_delegate_;
|
|
|
|
|
2010-10-03 23:04:50 +02:00
|
|
|
WebKit::WebWidget* webwidget_;
|
|
|
|
scoped_ptr<skia::PlatformCanvas> canvas_;
|
2011-10-03 17:48:32 +02:00
|
|
|
int canvas_w_;
|
|
|
|
int canvas_h_;
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2011-02-01 16:37:47 +01:00
|
|
|
// True if this widget is a popup widget.
|
|
|
|
bool popup_;
|
|
|
|
|
2011-03-24 21:36:47 +01:00
|
|
|
// Specifies the portion of the webwidget that needs painting.
|
2011-11-14 18:47:21 +01:00
|
|
|
// TODO(cef): Update the Linux port to use regions instead of rectangles.
|
|
|
|
#if defined(OS_WIN) || defined(OS_MACOSX)
|
2011-11-09 21:09:24 +01:00
|
|
|
SkRegion paint_rgn_;
|
|
|
|
#else
|
2010-10-03 23:04:50 +02:00
|
|
|
gfx::Rect paint_rect_;
|
2011-11-09 21:09:24 +01:00
|
|
|
#endif
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2012-08-21 21:48:29 +02:00
|
|
|
base::OneShotTimer<WebWidgetHost> timer_;
|
|
|
|
base::TimeTicks timer_last_;
|
|
|
|
bool timer_executing_;
|
|
|
|
bool timer_wanted_;
|
2012-08-15 01:33:57 +02:00
|
|
|
|
|
|
|
int64 frame_delay_;
|
2011-12-16 13:24:09 +01:00
|
|
|
|
|
|
|
#if defined(OS_WIN)
|
2012-08-13 18:27:44 +02:00
|
|
|
// Used to call UpdateImeInputState() while IME is active.
|
|
|
|
base::RepeatingTimer<WebWidgetHost> ime_timer_;
|
2011-12-16 13:24:09 +01:00
|
|
|
#endif
|
|
|
|
|
2011-03-24 21:36:47 +01:00
|
|
|
// The map of windowed plugins that need to be drawn when window rendering is
|
|
|
|
// disabled.
|
2012-01-10 00:46:23 +01:00
|
|
|
typedef std::map<gfx::PluginWindowHandle, webkit::npapi::WebPluginGeometry>
|
2011-03-24 21:36:47 +01:00
|
|
|
PluginMap;
|
|
|
|
PluginMap plugin_map_;
|
|
|
|
|
2010-10-09 20:23:06 +02:00
|
|
|
#if defined(OS_WIN)
|
2010-10-03 23:04:50 +02:00
|
|
|
bool track_mouse_leave_;
|
2010-11-22 18:49:46 +01:00
|
|
|
std::wstring tooltip_text_;
|
2011-03-24 21:36:47 +01:00
|
|
|
gfx::NativeView tooltip_view_;
|
|
|
|
bool tooltip_showing_;
|
2011-06-14 18:18:43 +02:00
|
|
|
|
|
|
|
// Wrapper class for IME input.
|
|
|
|
ui::ImeInput ime_input_;
|
|
|
|
|
2012-08-13 18:27:44 +02:00
|
|
|
// Represents whether or not this browser process is receiving status messages
|
|
|
|
// about the focused edit control from a renderer process.
|
2011-06-14 18:18:43 +02:00
|
|
|
bool ime_notification_;
|
|
|
|
|
2012-08-13 18:27:44 +02:00
|
|
|
// Stores the current text input type.
|
2011-06-14 18:18:43 +02:00
|
|
|
WebKit::WebTextInputType text_input_type_;
|
|
|
|
|
|
|
|
// Stores the current caret bounds of input focus.
|
|
|
|
WebKit::WebRect caret_bounds_;
|
2012-08-13 18:27:44 +02:00
|
|
|
#endif // OS_WIN
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2012-05-16 18:56:38 +02:00
|
|
|
#if defined(OS_MACOSX)
|
|
|
|
int mouse_modifiers_;
|
|
|
|
WebKit::WebMouseEvent::Button mouse_button_down_;
|
|
|
|
#endif
|
|
|
|
|
2010-10-09 20:23:06 +02:00
|
|
|
WebKit::WebKeyboardEvent last_key_event_;
|
2010-10-03 23:04:50 +02:00
|
|
|
|
|
|
|
bool painting_;
|
2011-10-26 16:21:49 +02:00
|
|
|
bool layouting_;
|
2012-08-15 01:33:57 +02:00
|
|
|
|
|
|
|
static const int kDefaultFrameRate;
|
|
|
|
static const int kMaxFrameRate;
|
2010-10-03 23:04:50 +02:00
|
|
|
};
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
#endif // CEF_LIBCEF_WEBWIDGET_HOST_H_
|