OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_VIEWS_H_ | |
6 #define CHROME_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_VIEWS_H_ | |
7 #pragma once | |
8 | |
9 #include <map> | |
10 #include <string> | |
11 #include <vector> | |
12 | |
13 #include "base/compiler_specific.h" | |
14 #include "base/memory/ref_counted.h" | |
15 #include "base/memory/weak_ptr.h" | |
16 #include "base/string16.h" | |
17 #include "base/time.h" | |
18 #include "content/browser/renderer_host/render_widget_host_view.h" | |
19 #include "content/public/browser/notification_observer.h" | |
20 #include "content/public/browser/notification_registrar.h" | |
21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | |
22 #include "ui/base/ime/text_input_client.h" | |
23 #include "ui/gfx/compositor/compositor_observer.h" | |
24 #include "ui/gfx/native_widget_types.h" | |
25 #include "ui/views/events/event.h" | |
26 #include "ui/views/touchui/touch_selection_controller.h" | |
27 #include "views/controls/native/native_view_host.h" | |
28 #include "views/view.h" | |
29 #include "webkit/glue/webcursor.h" | |
30 | |
31 #if defined(TOUCH_UI) | |
32 namespace ui { | |
33 enum TouchStatus; | |
34 } | |
35 #endif | |
36 | |
37 #if defined(UI_COMPOSITOR_IMAGE_TRANSPORT) | |
38 class AcceleratedSurfaceContainerLinux; | |
39 #endif | |
40 | |
41 class RenderWidgetHost; | |
42 | |
43 // ----------------------------------------------------------------------------- | |
44 // See comments in render_widget_host_view.h about this class and its members. | |
45 // ----------------------------------------------------------------------------- | |
46 class RenderWidgetHostViewViews : public RenderWidgetHostView, | |
47 #if defined(UI_COMPOSITOR_IMAGE_TRANSPORT) | |
48 public ui::CompositorObserver, | |
49 #endif | |
50 public views::TouchSelectionClientView, | |
51 public ui::TextInputClient, | |
52 public content::NotificationObserver { | |
53 public: | |
54 // Internal class name. | |
55 static const char kViewClassName[]; | |
56 | |
57 explicit RenderWidgetHostViewViews(RenderWidgetHost* widget); | |
58 virtual ~RenderWidgetHostViewViews(); | |
59 | |
60 // Initialize this object for use as a drawing area. | |
61 void InitAsChild(); | |
62 | |
63 // RenderWidgetHostView implementation. | |
64 virtual void InitAsPopup(RenderWidgetHostView* parent_host_view, | |
65 const gfx::Rect& pos) OVERRIDE; | |
66 virtual void InitAsFullscreen( | |
67 RenderWidgetHostView* reference_host_view) OVERRIDE; | |
68 virtual RenderWidgetHost* GetRenderWidgetHost() const OVERRIDE; | |
69 virtual void DidBecomeSelected() OVERRIDE; | |
70 virtual void WasHidden() OVERRIDE; | |
71 virtual void SetSize(const gfx::Size& size) OVERRIDE; | |
72 virtual void SetBounds(const gfx::Rect& rect) OVERRIDE; | |
73 virtual gfx::NativeView GetNativeView() const OVERRIDE; | |
74 virtual gfx::NativeViewId GetNativeViewId() const OVERRIDE; | |
75 virtual void MovePluginWindows( | |
76 const std::vector<webkit::npapi::WebPluginGeometry>& moves) OVERRIDE; | |
77 virtual bool HasFocus() const OVERRIDE; | |
78 virtual void Show() OVERRIDE; | |
79 virtual void Hide() OVERRIDE; | |
80 virtual bool IsShowing() OVERRIDE; | |
81 virtual gfx::Rect GetViewBounds() const OVERRIDE; | |
82 virtual void UpdateCursor(const WebCursor& cursor) OVERRIDE; | |
83 virtual void SetIsLoading(bool is_loading) OVERRIDE; | |
84 virtual void TextInputStateChanged(ui::TextInputType type, | |
85 bool can_compose_inline) OVERRIDE; | |
86 virtual void ImeCancelComposition() OVERRIDE; | |
87 virtual void DidUpdateBackingStore( | |
88 const gfx::Rect& scroll_rect, int scroll_dx, int scroll_dy, | |
89 const std::vector<gfx::Rect>& copy_rects) OVERRIDE; | |
90 virtual void RenderViewGone(base::TerminationStatus status, | |
91 int error_code) OVERRIDE; | |
92 virtual void Destroy() OVERRIDE; | |
93 virtual void SetTooltipText(const string16& tooltip_text) OVERRIDE; | |
94 virtual void SelectionChanged(const string16& text, | |
95 size_t offset, | |
96 const ui::Range& range) OVERRIDE; | |
97 virtual void SelectionBoundsChanged(const gfx::Rect& start_rect, | |
98 const gfx::Rect& end_rect) OVERRIDE; | |
99 virtual void ShowingContextMenu(bool showing) OVERRIDE; | |
100 virtual BackingStore* AllocBackingStore(const gfx::Size& size) OVERRIDE; | |
101 virtual void OnAcceleratedCompositingStateChange() OVERRIDE; | |
102 virtual void SetBackground(const SkBitmap& background) OVERRIDE; | |
103 #if defined(OS_POSIX) || defined(USE_AURA) | |
104 virtual void GetDefaultScreenInfo(WebKit::WebScreenInfo* results); | |
105 virtual void GetScreenInfo(WebKit::WebScreenInfo* results) OVERRIDE; | |
106 virtual gfx::Rect GetRootWindowBounds() OVERRIDE; | |
107 #endif | |
108 #if defined(TOOLKIT_USES_GTK) | |
109 virtual void CreatePluginContainer(gfx::PluginWindowHandle id) OVERRIDE; | |
110 virtual void DestroyPluginContainer(gfx::PluginWindowHandle id) OVERRIDE; | |
111 #endif | |
112 virtual void SetVisuallyDeemphasized(const SkColor* color, | |
113 bool animate) OVERRIDE; | |
114 virtual void UnhandledWheelEvent( | |
115 const WebKit::WebMouseWheelEvent& event) OVERRIDE; | |
116 virtual void SetHasHorizontalScrollbar( | |
117 bool has_horizontal_scrollbar) OVERRIDE; | |
118 virtual void SetScrollOffsetPinning( | |
119 bool is_pinned_to_left, bool is_pinned_to_right) OVERRIDE; | |
120 #if defined(OS_WIN) && !defined(USE_AURA) | |
121 virtual void WillWmDestroy() OVERRIDE; | |
122 #endif | |
123 virtual gfx::PluginWindowHandle GetCompositingSurface() OVERRIDE; | |
124 virtual bool LockMouse() OVERRIDE; | |
125 virtual void UnlockMouse() OVERRIDE; | |
126 | |
127 // Overridden from views::TouchSelectionClientView. | |
128 virtual void SelectRect(const gfx::Point& start, | |
129 const gfx::Point& end) OVERRIDE; | |
130 | |
131 // Overriden from content::NotificationObserver | |
132 virtual void Observe(int type, | |
133 const content::NotificationSource& source, | |
134 const content::NotificationDetails& details) OVERRIDE; | |
135 | |
136 // Overridden from ui::SimpleMenuModel::Delegate. | |
137 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE; | |
138 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE; | |
139 virtual bool GetAcceleratorForCommandId( | |
140 int command_id, | |
141 ui::Accelerator* accelerator) OVERRIDE; | |
142 virtual void ExecuteCommand(int command_id) OVERRIDE; | |
143 | |
144 // Overridden from views::View. | |
145 virtual std::string GetClassName() const OVERRIDE; | |
146 virtual gfx::NativeCursor GetCursor(const views::MouseEvent& event) OVERRIDE; | |
147 virtual bool OnMousePressed(const views::MouseEvent& event) OVERRIDE; | |
148 virtual bool OnMouseDragged(const views::MouseEvent& event) OVERRIDE; | |
149 virtual void OnMouseReleased(const views::MouseEvent& event) OVERRIDE; | |
150 virtual void OnMouseMoved(const views::MouseEvent& event) OVERRIDE; | |
151 virtual void OnMouseEntered(const views::MouseEvent& event) OVERRIDE; | |
152 virtual void OnMouseExited(const views::MouseEvent& event) OVERRIDE; | |
153 #if defined(TOUCH_UI) | |
154 virtual ui::TouchStatus OnTouchEvent(const views::TouchEvent& event) OVERRIDE; | |
155 #endif | |
156 virtual bool OnKeyPressed(const views::KeyEvent& event) OVERRIDE; | |
157 virtual bool OnKeyReleased(const views::KeyEvent& event) OVERRIDE; | |
158 virtual bool OnMouseWheel(const views::MouseWheelEvent& event) OVERRIDE; | |
159 virtual ui::TextInputClient* GetTextInputClient() OVERRIDE; | |
160 virtual bool GetTooltipText(const gfx::Point& p, | |
161 string16* tooltip) const OVERRIDE; | |
162 | |
163 // Overridden from ui::TextInputClient: | |
164 virtual void SetCompositionText( | |
165 const ui::CompositionText& composition) OVERRIDE; | |
166 virtual void ConfirmCompositionText() OVERRIDE; | |
167 virtual void ClearCompositionText() OVERRIDE; | |
168 virtual void InsertText(const string16& text) OVERRIDE; | |
169 virtual void InsertChar(char16 ch, int flags) OVERRIDE; | |
170 virtual ui::TextInputType GetTextInputType() const OVERRIDE; | |
171 virtual gfx::Rect GetCaretBounds() OVERRIDE; | |
172 virtual bool HasCompositionText() OVERRIDE; | |
173 virtual bool GetTextRange(ui::Range* range) OVERRIDE; | |
174 virtual bool GetCompositionTextRange(ui::Range* range) OVERRIDE; | |
175 virtual bool GetSelectionRange(ui::Range* range) OVERRIDE; | |
176 virtual bool SetSelectionRange(const ui::Range& range) OVERRIDE; | |
177 virtual bool DeleteRange(const ui::Range& range) OVERRIDE; | |
178 virtual bool GetTextFromRange(const ui::Range& range, | |
179 string16* text) OVERRIDE; | |
180 virtual void OnInputMethodChanged() OVERRIDE; | |
181 virtual bool ChangeTextDirectionAndLayoutAlignment( | |
182 base::i18n::TextDirection direction) OVERRIDE; | |
183 | |
184 #if defined(UI_COMPOSITOR_IMAGE_TRANSPORT) | |
185 virtual void AcceleratedSurfaceNew( | |
186 int32 width, | |
187 int32 height, | |
188 uint64* surface_id, | |
189 TransportDIB::Handle* surface_handle) OVERRIDE; | |
190 virtual void AcceleratedSurfaceBuffersSwapped( | |
191 uint64 surface_id, | |
192 int32 route_id, | |
193 int gpu_host_id) OVERRIDE; | |
194 virtual void AcceleratedSurfaceRelease(uint64 surface_id) OVERRIDE; | |
195 | |
196 // CompositorObserver implementation: | |
197 virtual void OnCompositingEnded(ui::Compositor* compositor) OVERRIDE; | |
198 #endif | |
199 | |
200 protected: | |
201 // Overridden from views::View. | |
202 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; | |
203 virtual void OnFocus() OVERRIDE; | |
204 virtual void OnBlur() OVERRIDE; | |
205 | |
206 // Overridden from RenderWidgetHostView | |
207 virtual void Focus() OVERRIDE; | |
208 virtual void Blur() OVERRIDE; | |
209 | |
210 private: | |
211 friend class RenderWidgetHostViewViewsWidget; | |
212 | |
213 // Returns whether the widget needs an input grab to work | |
214 // properly. | |
215 bool NeedsInputGrab(); | |
216 | |
217 // Returns whether this render view is a popup (<select> dropdown or | |
218 // autocomplete window). | |
219 bool IsPopup(); | |
220 | |
221 // Update the display cursor for the render view. | |
222 void ShowCurrentCursor(); | |
223 | |
224 // Translate a views::MouseEvent into a WebKit::WebMouseEvent. | |
225 WebKit::WebMouseEvent WebMouseEventFromViewsEvent( | |
226 const views::MouseEvent& event); | |
227 | |
228 // Confirm existing composition text in the webpage and ask the input method | |
229 // to cancel its ongoing composition sesstion. | |
230 void FinishImeCompositionSession(); | |
231 | |
232 // Updates the touch-selection controller (e.g. when the selection/focus | |
233 // changes). | |
234 void UpdateTouchSelectionController(); | |
235 | |
236 #if defined(TOOLKIT_USES_GTK) | |
237 // Returns true if the RWHV is ready to paint the content. | |
238 bool IsReadyToPaint(); | |
239 #endif | |
240 | |
241 // The model object. | |
242 RenderWidgetHost* host_; | |
243 | |
244 // This is true when we are currently painting and thus should handle extra | |
245 // paint requests by expanding the invalid rect rather than actually | |
246 // painting. | |
247 bool about_to_validate_and_paint_; | |
248 | |
249 // This is the rectangle which we'll paint. | |
250 gfx::Rect invalid_rect_; | |
251 | |
252 // Whether or not this widget is hidden. | |
253 bool is_hidden_; | |
254 | |
255 // Whether we are currently loading. | |
256 bool is_loading_; | |
257 | |
258 // The cursor for the page. This is passed up from the renderer. | |
259 WebCursor current_cursor_; | |
260 | |
261 // The native cursor. | |
262 gfx::NativeCursor native_cursor_; | |
263 | |
264 // Whether we are showing a context menu. | |
265 bool is_showing_context_menu_; | |
266 | |
267 // The time at which this view started displaying white pixels as a result of | |
268 // not having anything to paint (empty backing store from renderer). This | |
269 // value returns true for is_null() if we are not recording whiteout times. | |
270 base::TimeTicks whiteout_start_time_; | |
271 | |
272 // The time it took after this view was selected for it to be fully painted. | |
273 base::TimeTicks tab_switch_paint_time_; | |
274 | |
275 // If true, fade the render widget when painting it. | |
276 bool visually_deemphasized_; | |
277 | |
278 // The size that we want the renderer to be. | |
279 gfx::Size requested_size_; | |
280 | |
281 // The touch-event. Its touch-points are updated as necessary. A new | |
282 // touch-point is added from an ET_TOUCH_PRESSED event, and a touch-point is | |
283 // removed from the list on an ET_TOUCH_RELEASED event. | |
284 WebKit::WebTouchEvent touch_event_; | |
285 | |
286 // The current text input type. | |
287 ui::TextInputType text_input_type_; | |
288 | |
289 // Rectangles before and after the selection. | |
290 gfx::Rect selection_start_rect_; | |
291 gfx::Rect selection_end_rect_; | |
292 | |
293 // Indicates if there is onging composition text. | |
294 bool has_composition_text_; | |
295 | |
296 string16 tooltip_text_; | |
297 | |
298 #if defined(UI_COMPOSITOR_IMAGE_TRANSPORT) | |
299 std::vector< base::Callback<void(void)> > on_compositing_ended_callbacks_; | |
300 #endif | |
301 | |
302 scoped_ptr<views::TouchSelectionController> touch_selection_controller_; | |
303 base::WeakPtrFactory<RenderWidgetHostViewViews> weak_factory_; | |
304 | |
305 #if defined(TOUCH_UI) | |
306 // used to register for keyboard visiblity notificatons. | |
307 content::NotificationRegistrar registrar_; | |
308 gfx::Rect keyboard_rect_; | |
309 #endif | |
310 | |
311 #if defined(UI_COMPOSITOR_IMAGE_TRANSPORT) | |
312 std::map<uint64, scoped_refptr<AcceleratedSurfaceContainerLinux> > | |
313 accelerated_surface_containers_; | |
314 #endif | |
315 | |
316 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewViews); | |
317 }; | |
318 | |
319 #endif // CHROME_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_VIEWS_H_ | |
OLD | NEW |