Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(33)

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_gtk.h

Issue 231733005: Delete the GTK+ port of Chrome. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remerge to ToT Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 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 CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_GTK_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_GTK_H_
7
8 #include <gdk/gdk.h>
9
10 #include <string>
11 #include <vector>
12
13 #include "base/memory/scoped_ptr.h"
14 #include "base/time/time.h"
15 #include "content/browser/accessibility/browser_accessibility_manager.h"
16 #include "content/browser/renderer_host/gtk_plugin_container_manager.h"
17 #include "content/browser/renderer_host/render_widget_host_view_base.h"
18 #include "content/common/content_export.h"
19 #include "content/common/cursors/webcursor.h"
20 #include "ipc/ipc_sender.h"
21 #include "ui/base/gtk/gtk_signal.h"
22 #include "ui/base/gtk/gtk_signal_registrar.h"
23 #include "ui/base/gtk/owned_widget_gtk.h"
24 #include "ui/base/x/active_window_watcher_x_observer.h"
25 #include "ui/gfx/native_widget_types.h"
26 #include "ui/gfx/point.h"
27 #include "ui/gfx/rect.h"
28
29 typedef struct _GtkClipboard GtkClipboard;
30 typedef struct _GtkSelectionData GtkSelectionData;
31
32 namespace content {
33 class GtkIMContextWrapper;
34 class GtkKeyBindingsHandler;
35 class RenderWidgetHost;
36 class RenderWidgetHostImpl;
37 struct NativeWebKeyboardEvent;
38
39 // -----------------------------------------------------------------------------
40 // See comments in render_widget_host_view.h about this class and its members.
41 // -----------------------------------------------------------------------------
42 class CONTENT_EXPORT RenderWidgetHostViewGtk
43 : public RenderWidgetHostViewBase,
44 public BrowserAccessibilityDelegate,
45 public ui::ActiveWindowWatcherXObserver,
46 public IPC::Sender {
47 public:
48 virtual ~RenderWidgetHostViewGtk();
49
50 // RenderWidgetHostView implementation.
51 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
52 virtual void InitAsChild(gfx::NativeView parent_view) OVERRIDE;
53 virtual RenderWidgetHost* GetRenderWidgetHost() const OVERRIDE;
54 virtual void SetSize(const gfx::Size& size) OVERRIDE;
55 virtual void SetBounds(const gfx::Rect& rect) OVERRIDE;
56 virtual gfx::NativeView GetNativeView() const OVERRIDE;
57 virtual gfx::NativeViewId GetNativeViewId() const OVERRIDE;
58 virtual gfx::NativeViewAccessible GetNativeViewAccessible() OVERRIDE;
59 virtual bool HasFocus() const OVERRIDE;
60 virtual bool IsSurfaceAvailableForCopy() const OVERRIDE;
61 virtual void Show() OVERRIDE;
62 virtual void Hide() OVERRIDE;
63 virtual bool IsShowing() OVERRIDE;
64 virtual gfx::Rect GetViewBounds() const OVERRIDE;
65 virtual GdkEventButton* GetLastMouseDown() OVERRIDE;
66 virtual gfx::NativeView BuildInputMethodsGtkMenu() OVERRIDE;
67 virtual void SetBackground(const SkBitmap& background) OVERRIDE;
68
69 // RenderWidgetHostViewPort implementation.
70 virtual void InitAsPopup(RenderWidgetHostView* parent_host_view,
71 const gfx::Rect& pos) OVERRIDE;
72 virtual void InitAsFullscreen(
73 RenderWidgetHostView* reference_host_view) OVERRIDE;
74 virtual void WasShown() OVERRIDE;
75 virtual void WasHidden() OVERRIDE;
76 virtual void MovePluginWindows(
77 const gfx::Vector2d& scroll_offset,
78 const std::vector<WebPluginGeometry>& moves) OVERRIDE;
79 virtual void Focus() OVERRIDE;
80 virtual void Blur() OVERRIDE;
81 virtual void UpdateCursor(const WebCursor& cursor) OVERRIDE;
82 virtual void SetIsLoading(bool is_loading) OVERRIDE;
83 virtual void TextInputTypeChanged(ui::TextInputType type,
84 ui::TextInputMode input_mode,
85 bool can_compose_inline) OVERRIDE;
86 virtual void ImeCancelComposition() OVERRIDE;
87 virtual void DidUpdateBackingStore(
88 const gfx::Rect& scroll_rect,
89 const gfx::Vector2d& scroll_delta,
90 const std::vector<gfx::Rect>& copy_rects,
91 const std::vector<ui::LatencyInfo>& latency_info) OVERRIDE;
92 virtual void RenderProcessGone(base::TerminationStatus status,
93 int error_code) OVERRIDE;
94 virtual void Destroy() OVERRIDE;
95 virtual void WillDestroyRenderWidget(RenderWidgetHost* rwh) {}
96 virtual void SetTooltipText(const base::string16& tooltip_text) OVERRIDE;
97 virtual void SelectionChanged(const base::string16& text,
98 size_t offset,
99 const gfx::Range& range) OVERRIDE;
100 virtual void SelectionBoundsChanged(
101 const ViewHostMsg_SelectionBounds_Params& params) OVERRIDE;
102 virtual void ScrollOffsetChanged() OVERRIDE;
103 virtual BackingStore* AllocBackingStore(const gfx::Size& size) OVERRIDE;
104 virtual void CopyFromCompositingSurface(
105 const gfx::Rect& src_subrect,
106 const gfx::Size& dst_size,
107 const base::Callback<void(bool, const SkBitmap&)>& callback,
108 SkBitmap::Config config) OVERRIDE;
109 virtual void CopyFromCompositingSurfaceToVideoFrame(
110 const gfx::Rect& src_subrect,
111 const scoped_refptr<media::VideoFrame>& target,
112 const base::Callback<void(bool)>& callback) OVERRIDE;
113 virtual bool CanCopyToVideoFrame() const OVERRIDE;
114 virtual void OnAcceleratedCompositingStateChange() OVERRIDE;
115 virtual void AcceleratedSurfaceInitialized(int host_id,
116 int route_id) OVERRIDE;
117 virtual void AcceleratedSurfaceBuffersSwapped(
118 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params,
119 int gpu_host_id) OVERRIDE;
120 virtual void AcceleratedSurfacePostSubBuffer(
121 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params,
122 int gpu_host_id) OVERRIDE;
123 virtual void AcceleratedSurfaceSuspend() OVERRIDE;
124 virtual void AcceleratedSurfaceRelease() OVERRIDE;
125 virtual bool HasAcceleratedSurface(const gfx::Size& desired_size) OVERRIDE;
126 virtual void SetHasHorizontalScrollbar(
127 bool has_horizontal_scrollbar) OVERRIDE;
128 virtual void SetScrollOffsetPinning(
129 bool is_pinned_to_left, bool is_pinned_to_right) OVERRIDE;
130 virtual void GetScreenInfo(blink::WebScreenInfo* results) OVERRIDE;
131 virtual gfx::Rect GetBoundsInRootWindow() OVERRIDE;
132 virtual gfx::GLSurfaceHandle GetCompositingSurface() OVERRIDE;
133 virtual void ResizeCompositingSurface(const gfx::Size&) OVERRIDE;
134 virtual bool LockMouse() OVERRIDE;
135 virtual void UnlockMouse() OVERRIDE;
136 virtual void CreateBrowserAccessibilityManagerIfNeeded() OVERRIDE;
137
138 // ActiveWindowWatcherXObserver implementation.
139 virtual void ActiveWindowChanged(GdkWindow* active_window) OVERRIDE;
140
141 // IPC::Sender implementation:
142 virtual bool Send(IPC::Message* message) OVERRIDE;
143
144 // If the widget is aligned with an edge of the monitor its on and the user
145 // attempts to drag past that edge we track the number of times it has
146 // occurred, so that we can force the widget to scroll when it otherwise
147 // would be unable to.
148 void ModifyEventForEdgeDragging(GtkWidget* widget, GdkEventMotion* event);
149
150 // Mouse events always provide a movementX/Y which needs to be computed.
151 // Also, mouse lock requires knowledge of last unlocked cursor coordinates.
152 // State is stored on the host view to do this, and the mouse event modified.
153 void ModifyEventMovementAndCoords(blink::WebMouseEvent* event);
154
155 void Paint(const gfx::Rect&);
156
157 // Called by GtkIMContextWrapper to forward a keyboard event to renderer.
158 // On Linux (not ChromeOS):
159 // Before calling RenderWidgetHost::ForwardKeyboardEvent(), this method
160 // calls GtkKeyBindingsHandler::Match() against the event and send matched
161 // edit commands to renderer by calling
162 // RenderWidgetHost::ForwardEditCommandsForNextKeyEvent().
163 void ForwardKeyboardEvent(const NativeWebKeyboardEvent& event);
164
165 bool RetrieveSurrounding(std::string* text, size_t* cursor_index);
166
167 // BrowserAccessibilityDelegate implementation.
168 virtual void SetAccessibilityFocus(int acc_obj_id) OVERRIDE;
169 virtual void AccessibilityDoDefaultAction(int acc_obj_id) OVERRIDE;
170 virtual void AccessibilityScrollToMakeVisible(
171 int acc_obj_id, gfx::Rect subfocus) OVERRIDE;
172 virtual void AccessibilityScrollToPoint(
173 int acc_obj_id, gfx::Point point) OVERRIDE;
174 virtual void AccessibilitySetTextSelection(
175 int acc_obj_id, int start_offset, int end_offset) OVERRIDE;
176 virtual gfx::Point GetLastTouchEventLocation() const OVERRIDE;
177 virtual void FatalAccessibilityTreeError() OVERRIDE;
178
179 virtual SkBitmap::Config PreferredReadbackFormat() OVERRIDE;
180
181 // Get the root of the AtkObject* tree for accessibility.
182 AtkObject* GetAccessible();
183
184 protected:
185 friend class RenderWidgetHostView;
186
187 // Should construct only via RenderWidgetHostView::CreateViewForWidget.
188 explicit RenderWidgetHostViewGtk(RenderWidgetHost* widget);
189
190 private:
191 friend class RenderWidgetHostViewGtkWidget;
192
193 CHROMEGTK_CALLBACK_0(RenderWidgetHostViewGtk,
194 void,
195 OnDestroy);
196
197 // Returns whether the widget needs an input grab (GTK+ and X) to work
198 // properly.
199 bool NeedsInputGrab();
200
201 // Returns whether this render view is a popup (<select> dropdown or
202 // autocomplete window).
203 bool IsPopup() const;
204
205 // Do initialization needed by all InitAs*() methods.
206 void DoSharedInit();
207
208 // Do initialization needed just by InitAsPopup() and InitAsFullscreen().
209 // We move and resize |window| to |bounds| and show it and its contents.
210 void DoPopupOrFullscreenInit(GtkWindow* window, const gfx::Rect& bounds);
211
212 // Update the display cursor for the render view.
213 void ShowCurrentCursor();
214
215 void set_last_mouse_down(GdkEventButton* event);
216
217 // Cause the next query for the widget center to recompute the cached value.
218 void MarkCachedWidgetCenterStale();
219
220 void OnCreatePluginContainer(gfx::PluginWindowHandle id);
221 void OnDestroyPluginContainer(gfx::PluginWindowHandle id);
222
223 gfx::Point GetWidgetCenter();
224
225 // The model object.
226 RenderWidgetHostImpl* host_;
227
228 // The native UI widget.
229 ui::OwnedWidgetGtk view_;
230
231 // This is true when we are currently painting and thus should handle extra
232 // paint requests by expanding the invalid rect rather than actually
233 // painting.
234 bool about_to_validate_and_paint_;
235
236 // This is the rectangle which we'll paint.
237 gfx::Rect invalid_rect_;
238
239 // Whether we are currently loading.
240 bool is_loading_;
241
242 // The cursor for the page. This is passed up from the renderer.
243 WebCursor current_cursor_;
244
245 // The time at which this view started displaying white pixels as a result of
246 // not having anything to paint (empty backing store from renderer). This
247 // value returns true for is_null() if we are not recording whiteout times.
248 base::TimeTicks whiteout_start_time_;
249
250 // The time it took after this view was selected for it to be fully painted.
251 base::TimeTicks web_contents_switch_paint_time_;
252
253 // The native view of our parent widget. Used only for popups.
254 GtkWidget* parent_;
255
256 // We ignore the first mouse release on popups so the popup will remain open.
257 bool is_popup_first_mouse_release_;
258
259 // Whether or not this widget's input context was focused before being
260 // shadowed by another widget. Used in OnGrabNotify() handler to track the
261 // focused state correctly.
262 bool was_imcontext_focused_before_grab_;
263
264 // True if we are responsible for creating an X grab. This will only be used
265 // for <select> dropdowns. It should be true for most such cases, but false
266 // for extension popups.
267 bool do_x_grab_;
268
269 // Is the widget fullscreen?
270 bool is_fullscreen_;
271
272 // Has the window ever been marked active? Only valid for fullscreen or
273 // popup windows.
274 bool made_active_;
275
276 // Used to record the last position of the mouse.
277 // While the mouse is locked, they store the last known position just as mouse
278 // lock was entered.
279 // Relative to the upper-left corner of the view.
280 gfx::Point unlocked_mouse_position_;
281 // Relative to the upper-left corner of the screen.
282 gfx::Point unlocked_global_mouse_position_;
283 // Last hidden cursor position. Relative to screen.
284 gfx::Point global_mouse_position_;
285 // Indicates when mouse motion is valid after the widget has moved.
286 bool mouse_has_been_warped_to_new_center_;
287 // Indicates the cursor has been warped to the unlocked position,
288 // but a move event has not yet been received for it there.
289 bool mouse_is_being_warped_to_unlocked_position_;
290
291 // For full-screen windows we have a OnDestroy handler that we need to remove,
292 // so we keep it ID here.
293 unsigned long destroy_handler_id_;
294
295 // A convenience wrapper object for GtkIMContext;
296 scoped_ptr<GtkIMContextWrapper> im_context_;
297
298 // A convenience object for handling editor key bindings defined in gtk
299 // keyboard theme.
300 scoped_ptr<GtkKeyBindingsHandler> key_bindings_handler_;
301
302 // Helper class that lets us allocate plugin containers and move them.
303 GtkPluginContainerManager plugin_container_manager_;
304
305 // The size that we want the renderer to be. We keep this in a separate
306 // variable because resizing in GTK+ is async.
307 gfx::Size requested_size_;
308
309 // The latest reported center of the widget, use GetWidgetCenter() to access.
310 gfx::Point widget_center_;
311 // If the window moves the widget_center will not be valid until we recompute.
312 bool widget_center_valid_;
313
314 // The number of times the user has dragged against horizontal edge of the
315 // monitor (if the widget is aligned with that edge). Negative values
316 // indicate the left edge, positive the right.
317 int dragged_at_horizontal_edge_;
318
319 // The number of times the user has dragged against vertical edge of the
320 // monitor (if the widget is aligned with that edge). Negative values
321 // indicate the top edge, positive the bottom.
322 int dragged_at_vertical_edge_;
323
324 gfx::PluginWindowHandle compositing_surface_;
325
326 // The event for the last mouse down we handled. We need this for context
327 // menus and drags.
328 GdkEventButton* last_mouse_down_;
329
330 // Instance of accessibility information for the root of the AtkObject
331 // tree representation of the WebKit render tree.
332 scoped_ptr<BrowserAccessibilityManager> browser_accessibility_manager_;
333
334 ui::GtkSignalRegistrar signals_;
335
336 std::vector<ui::LatencyInfo> software_latency_info_;
337 };
338
339 } // namespace content
340
341 #endif // CHROME_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_GTK_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698