blob: 4bd827a4581004e389dd3dd33c68945677d01773 [file] [log] [blame]
// 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 <map>
#include <string>
#include <vector>
#include "base/memory/ref_counted.h"
#include "base/time.h"
#include "content/browser/renderer_host/render_widget_host_view.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.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,
public views::TouchSelectionClientView,
public views::TextInputClient {
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<webkit::npapi::WebPluginGeometry>& 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<gfx::Rect>& copy_rects) OVERRIDE;
virtual void RenderViewGone(base::TerminationStatus status,
int error_code) OVERRIDE;
virtual void Destroy() OVERRIDE;
virtual void SetTooltipText(const std::wstring& 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 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;
// Overridden from views::TouchSelectionClientView.
virtual void SelectRect(const gfx::Point& start,
const gfx::Point& end) 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, std::wstring* 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() 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<void(const string16&)>& 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 AcceleratedSurfaceSetIOSurface(
int32 width, int32 height, uint64 surface_id) OVERRIDE;
virtual void AcceleratedSurfaceBuffersSwapped(uint64 surface_id) OVERRIDE;
virtual void AcceleratedSurfaceRelease(uint64 surface_id) OVERRIDE;
#endif
protected:
// Overridden 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 (<select> dropdown or
// autocomplete window).
bool IsPopup();
// Update the display cursor for the render view.
void ShowCurrentCursor();
// Translate a views::MouseEvent into a WebKit::WebMouseEvent.
WebKit::WebMouseEvent WebMouseEventFromViewsEvent(
const views::MouseEvent& event);
// Confirm existing composition text in the webpage and ask the input method
// to cancel its ongoing composition sesstion.
void FinishImeCompositionSession();
#if defined(TOOLKIT_USES_GTK)
// On some systems, there can be two native views, where an outer native view
// contains the inner native view (e.g. when using GTK+). This returns the
// inner view. This can return NULL when it's not attached to a view.
gfx::NativeView GetInnerNativeView() const;
#endif
// The model object.
RenderWidgetHost* host_;
// This is true when we are currently painting and thus should handle extra
// paint requests by expanding the invalid rect rather than actually
// painting.
bool about_to_validate_and_paint_;
// This is the rectangle which we'll paint.
gfx::Rect invalid_rect_;
// Whether or not this widget is hidden.
bool is_hidden_;
// Whether we are currently loading.
bool is_loading_;
// The cursor for the page. This is passed up from the renderer.
WebCursor current_cursor_;
// The native cursor.
gfx::NativeCursor native_cursor_;
// Whether we are showing a context menu.
bool is_showing_context_menu_;
// The time at which this view started displaying white pixels as a result of
// not having anything to paint (empty backing store from renderer). This
// value returns true for is_null() if we are not recording whiteout times.
base::TimeTicks whiteout_start_time_;
// The time it took after this view was selected for it to be fully painted.
base::TimeTicks tab_switch_paint_time_;
// If true, fade the render widget when painting it.
bool visually_deemphasized_;
// The size that we want the renderer to be.
gfx::Size requested_size_;
// The touch-event. Its touch-points are updated as necessary. A new
// touch-point is added from an ET_TOUCH_PRESSED event, and a touch-point is
// removed from the list on an ET_TOUCH_RELEASED event.
WebKit::WebTouchEvent touch_event_;
// The current text input type.
ui::TextInputType text_input_type_;
// The current caret bounds.
gfx::Rect caret_bounds_;
// Indicates if there is onging composition text.
bool has_composition_text_;
string16 tooltip_text_;
scoped_ptr<views::TouchSelectionController> touch_selection_controller_;
gfx::Point selection_start_;
gfx::Point selection_end_;
#if defined(TOUCH_UI)
std::map<uint64, scoped_refptr<AcceleratedSurfaceContainerTouch> >
accelerated_surface_containers_;
#endif
DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewViews);
};
#endif // CHROME_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_VIEWS_H_