// 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 CHROME_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_VIEWS_H_ #define CHROME_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_VIEWS_H_ #pragma once #include #include #include #include "base/memory/ref_counted.h" #include "base/time.h" #include "content/browser/renderer_host/render_widget_host_view.h" #include "content/common/notification_observer.h" #include "content/common/notification_registrar.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" #include "ui/gfx/compositor/compositor_observer.h" #include "ui/gfx/native_widget_types.h" #include "views/controls/native/native_view_host.h" #include "views/events/event.h" #include "views/ime/text_input_client.h" #include "views/touchui/touch_selection_controller.h" #include "views/view.h" #include "webkit/glue/webcursor.h" #if defined(TOUCH_UI) namespace ui { enum TouchStatus; } class AcceleratedSurfaceContainerTouch; #endif class RenderWidgetHost; struct NativeWebKeyboardEvent; // ----------------------------------------------------------------------------- // See comments in render_widget_host_view.h about this class and its members. // ----------------------------------------------------------------------------- class RenderWidgetHostViewViews : public RenderWidgetHostView, #if defined(TOUCH_UI) public ui::CompositorObserver, #endif public views::TouchSelectionClientView, public views::TextInputClient, public NotificationObserver { public: // Internal class name. static const char kViewClassName[]; explicit RenderWidgetHostViewViews(RenderWidgetHost* widget); virtual ~RenderWidgetHostViewViews(); // Initialize this object for use as a drawing area. void InitAsChild(); // RenderWidgetHostView implementation. virtual void InitAsPopup(RenderWidgetHostView* parent_host_view, const gfx::Rect& pos) OVERRIDE; virtual void InitAsFullscreen( RenderWidgetHostView* reference_host_view) OVERRIDE; virtual RenderWidgetHost* GetRenderWidgetHost() const OVERRIDE; virtual void DidBecomeSelected() OVERRIDE; virtual void WasHidden() OVERRIDE; virtual void SetSize(const gfx::Size& size) OVERRIDE; virtual void SetBounds(const gfx::Rect& rect) OVERRIDE; virtual gfx::NativeView GetNativeView() const OVERRIDE; virtual gfx::NativeViewId GetNativeViewId() const OVERRIDE; virtual void MovePluginWindows( const std::vector& moves) OVERRIDE; virtual bool HasFocus() OVERRIDE; virtual void Show() OVERRIDE; virtual void Hide() OVERRIDE; virtual bool IsShowing() OVERRIDE; virtual gfx::Rect GetViewBounds() const OVERRIDE; virtual void UpdateCursor(const WebCursor& cursor) OVERRIDE; virtual void SetIsLoading(bool is_loading) OVERRIDE; virtual void ImeUpdateTextInputState(ui::TextInputType type, bool can_compose_inline, const gfx::Rect& caret_rect) OVERRIDE; virtual void ImeCancelComposition() OVERRIDE; virtual void DidUpdateBackingStore( const gfx::Rect& scroll_rect, int scroll_dx, int scroll_dy, const std::vector& copy_rects) OVERRIDE; virtual void RenderViewGone(base::TerminationStatus status, int error_code) OVERRIDE; virtual void Destroy() OVERRIDE; virtual void SetTooltipText(const string16& tooltip_text) OVERRIDE; virtual void SelectionChanged(const std::string& text, const ui::Range& range, const gfx::Point& start, const gfx::Point& end) OVERRIDE; virtual void ShowingContextMenu(bool showing) OVERRIDE; virtual BackingStore* AllocBackingStore(const gfx::Size& size) OVERRIDE; virtual void SetBackground(const SkBitmap& background) OVERRIDE; #if defined(OS_POSIX) virtual void GetDefaultScreenInfo(WebKit::WebScreenInfo* results); virtual void GetScreenInfo(WebKit::WebScreenInfo* results) OVERRIDE; virtual gfx::Rect GetRootWindowBounds() OVERRIDE; #endif #if defined(TOOLKIT_USES_GTK) virtual void CreatePluginContainer(gfx::PluginWindowHandle id) OVERRIDE; virtual void DestroyPluginContainer(gfx::PluginWindowHandle id) OVERRIDE; #endif virtual void SetVisuallyDeemphasized(const SkColor* color, bool animate) OVERRIDE; virtual void UnhandledWheelEvent( const WebKit::WebMouseWheelEvent& event) OVERRIDE; virtual void SetHasHorizontalScrollbar( bool has_horizontal_scrollbar) OVERRIDE; virtual void SetScrollOffsetPinning( bool is_pinned_to_left, bool is_pinned_to_right) OVERRIDE; #if defined(TOOLKIT_USES_GTK) virtual void AcceleratedCompositingActivated(bool activated) OVERRIDE; #endif #if defined(OS_WIN) virtual void WillWmDestroy() OVERRIDE; virtual void ShowCompositorHostWindow(bool show) OVERRIDE; #endif virtual gfx::PluginWindowHandle GetCompositingSurface() OVERRIDE; virtual bool LockMouse() OVERRIDE; virtual void UnlockMouse() OVERRIDE; // Overridden from views::TouchSelectionClientView. virtual void SelectRect(const gfx::Point& start, const gfx::Point& end) OVERRIDE; // Overriden from NotificationObserver virtual void Observe(int type, const NotificationSource& source, const NotificationDetails& details) OVERRIDE; // Overridden from ui::SimpleMenuModel::Delegate. virtual bool IsCommandIdChecked(int command_id) const OVERRIDE; virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE; virtual bool GetAcceleratorForCommandId( int command_id, ui::Accelerator* accelerator) OVERRIDE; virtual void ExecuteCommand(int command_id) OVERRIDE; // Overridden from views::View. virtual std::string GetClassName() const OVERRIDE; virtual gfx::NativeCursor GetCursor(const views::MouseEvent& event) OVERRIDE; virtual bool OnMousePressed(const views::MouseEvent& event) OVERRIDE; virtual bool OnMouseDragged(const views::MouseEvent& event) OVERRIDE; virtual void OnMouseReleased(const views::MouseEvent& event) OVERRIDE; virtual void OnMouseMoved(const views::MouseEvent& event) OVERRIDE; virtual void OnMouseEntered(const views::MouseEvent& event) OVERRIDE; virtual void OnMouseExited(const views::MouseEvent& event) OVERRIDE; #if defined(TOUCH_UI) virtual ui::TouchStatus OnTouchEvent(const views::TouchEvent& event) OVERRIDE; #endif virtual bool OnKeyPressed(const views::KeyEvent& event) OVERRIDE; virtual bool OnKeyReleased(const views::KeyEvent& event) OVERRIDE; virtual bool OnMouseWheel(const views::MouseWheelEvent& event) OVERRIDE; virtual views::TextInputClient* GetTextInputClient() OVERRIDE; virtual bool GetTooltipText(const gfx::Point& p, string16* tooltip) OVERRIDE; // Overridden from TextInputClient: virtual void SetCompositionText( const ui::CompositionText& composition) OVERRIDE; virtual void ConfirmCompositionText() OVERRIDE; virtual void ClearCompositionText() OVERRIDE; virtual void InsertText(const string16& text) OVERRIDE; virtual void InsertChar(char16 ch, int flags) OVERRIDE; virtual ui::TextInputType GetTextInputType() const OVERRIDE; virtual gfx::Rect GetCaretBounds() OVERRIDE; virtual bool HasCompositionText() OVERRIDE; virtual bool GetTextRange(ui::Range* range) OVERRIDE; virtual bool GetCompositionTextRange(ui::Range* range) OVERRIDE; virtual bool GetSelectionRange(ui::Range* range) OVERRIDE; virtual bool SetSelectionRange(const ui::Range& range) OVERRIDE; virtual bool DeleteRange(const ui::Range& range) OVERRIDE; virtual bool GetTextFromRange( const ui::Range& range, const base::Callback& callback) OVERRIDE; virtual void OnInputMethodChanged() OVERRIDE; virtual bool ChangeTextDirectionAndLayoutAlignment( base::i18n::TextDirection direction) OVERRIDE; virtual views::View* GetOwnerViewOfTextInputClient() OVERRIDE; #if defined(TOUCH_UI) virtual void AcceleratedSurfaceNew( int32 width, int32 height, uint64* surface_id, TransportDIB::Handle* surface_handle) OVERRIDE; virtual void AcceleratedSurfaceBuffersSwapped( uint64 surface_id, int32 route_id, int gpu_host_id) OVERRIDE; virtual void AcceleratedSurfaceRelease(uint64 surface_id) OVERRIDE; // CompositorObserver implementation: virtual void OnCompositingEnded(ui::Compositor* compositor) OVERRIDE; #endif protected: // Overridden from views::View. virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; virtual void OnFocus() OVERRIDE; virtual void OnBlur() OVERRIDE; // Overridden from RenderWidgetHostView virtual void Focus() OVERRIDE; virtual void Blur() OVERRIDE; private: friend class RenderWidgetHostViewViewsWidget; // Returns whether the widget needs an input grab to work // properly. bool NeedsInputGrab(); // Returns whether this render view is a popup (