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

Side by Side Diff: ui/views/widget/native_widget_gtk.h

Issue 9728002: Removing deprecated GTK-Views code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 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
« no previous file with comments | « ui/views/widget/gtk_views_window.cc ('k') | ui/views/widget/native_widget_gtk.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 UI_VIEWS_WIDGET_NATIVE_WIDGET_GTK_H_
6 #define UI_VIEWS_WIDGET_NATIVE_WIDGET_GTK_H_
7 #pragma once
8
9 #include <gtk/gtk.h>
10
11 #include "base/compiler_specific.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/message_loop.h"
15 #include "ui/base/gtk/gtk_signal.h"
16 #include "ui/base/x/active_window_watcher_x_observer.h"
17 #include "ui/gfx/size.h"
18 #include "ui/views/focus/focus_manager.h"
19 #include "ui/views/widget/native_widget_private.h"
20 #include "ui/views/widget/widget.h"
21
22 namespace gfx {
23 class Rect;
24 }
25
26 namespace ui {
27 class OSExchangeData;
28 class OSExchangeDataProviderGtk;
29 class GtkSignalRegistrar;
30 }
31 using ui::OSExchangeData;
32 using ui::OSExchangeDataProviderGtk;
33
34 namespace views {
35
36 class DropTargetGtk;
37 class InputMethod;
38 class View;
39
40 namespace internal {
41 class NativeWidgetDelegate;
42 }
43
44 // Widget implementation for GTK.
45 class VIEWS_EXPORT NativeWidgetGtk : public internal::NativeWidgetPrivate,
46 public ui::ActiveWindowWatcherXObserver {
47 public:
48 explicit NativeWidgetGtk(internal::NativeWidgetDelegate* delegate);
49 virtual ~NativeWidgetGtk();
50
51 // Returns the transient parent. See make_transient_to_parent for details on
52 // what the transient parent is.
53 GtkWindow* GetTransientParent() const;
54
55 // Makes the background of the window totally transparent. This must be
56 // invoked before Init. This does a couple of checks and returns true if
57 // the window can be made transparent. The actual work of making the window
58 // transparent is done by ConfigureWidgetForTransparentBackground.
59 // This works for both child and window types.
60 bool MakeTransparent();
61 bool is_transparent() const { return transparent_; }
62
63 // Enable/Disable double buffering.This is neccessary to prevent
64 // flickering in ScrollView, which has both native and view
65 // controls.
66 void EnableDoubleBuffer(bool enabled);
67 bool is_double_buffered() const { return is_double_buffered_; }
68
69 bool is_ignore_events() const { return ignore_events_; }
70
71 // Adds and removes the specified widget as a child of this widget's contents.
72 // These methods make sure to add the widget to the window's contents
73 // container if this widget is a window.
74 void AddChild(GtkWidget* child);
75 void RemoveChild(GtkWidget* child);
76
77 // A safe way to reparent a child widget to this widget. Calls
78 // gtk_widget_reparent which handles refcounting to avoid destroying the
79 // widget when removing it from its old parent.
80 void ReparentChild(GtkWidget* child);
81
82 // Positions a child GtkWidget at the specified location and bounds.
83 void PositionChild(GtkWidget* child, int x, int y, int w, int h);
84
85 // Parent GtkWidget all children are added to. When this NativeWidgetGtk
86 // corresponds to a top level window, this is the GtkFixed within the
87 // GtkWindow, not the GtkWindow itself. For child widgets, this is the same
88 // GtkFixed as |widget_|.
89 GtkWidget* window_contents() const { return window_contents_; }
90
91 // Starts a drag on this widget. This blocks until the drag is done.
92 void DoDrag(const OSExchangeData& data, int operation);
93
94 // Invoked when the active status changes.
95 virtual void OnActiveChanged();
96
97 // Sets the drop target to NULL. This is invoked by DropTargetGTK when the
98 // drop is done.
99 void ResetDropTarget();
100
101 // Gets the requested size of the widget. This can be the size
102 // stored in properties for a GtkViewsFixed, or in the requisitioned
103 // size of other kinds of widgets.
104 void GetRequestedSize(gfx::Size* out) const;
105
106 // Overridden from ui::ActiveWindowWatcherXObserver.
107 virtual void ActiveWindowChanged(GdkWindow* active_window) OVERRIDE;
108
109 // Handles a keyboard event by sending it to our focus manager.
110 // Returns true if it's handled by the focus manager.
111 bool HandleKeyboardEvent(const KeyEvent& key);
112
113 // Tells widget not to remove FREEZE_UPDATES property when the
114 // widget is painted. This is used if painting the gtk widget
115 // is not enough to show the window and has to wait further like
116 // keyboard overlay. Returns true if this is called before
117 // FREEZE_UPDATES property is removed, or false otherwise.
118 bool SuppressFreezeUpdates();
119
120 // Sets and deletes FREEZE_UPDATES property on given |window|.
121 // It adds the property when |enable| is true and remove if false.
122 // Calling this method will realize the window if it's not realized yet.
123 // This property is used to help WindowManager know when the window
124 // is fully painted so that WM can map the fully painted window.
125 // The property is based on Owen Taylor's proposal at
126 // http://mail.gnome.org/archives/wm-spec-list/2009-June/msg00002.html.
127 // This is just a hint to WM, and won't change the behavior for WM
128 // which does not support this property.
129 static void UpdateFreezeUpdatesProperty(GtkWindow* window, bool enable);
130
131 // Registers/Unregisters a expose handler that removes
132 // FREEZE_UPDATES property. If you are adding a GtkWidget with its
133 // own GdkWindow that may fill the entire area of the
134 // NativeWidgetGtk to the view hierachy, you need use this function
135 // to tell WM that when the widget is ready to be shown. Caller of
136 // this method do not need to unregister the handler if the widget
137 // receives the expose event for sure because the handler will be
138 // removed upon the first invocation of the handler. If the
139 // widget may be detached without expose event, the caller must
140 // unregister the handler using/ UnregisterChildExposeHandler.
141 static void RegisterChildExposeHandler(GtkWidget* widget);
142 static void UnregisterChildExposeHandler(GtkWidget* widget);
143
144 // Overridden from internal::NativeWidgetPrivate:
145 virtual void InitNativeWidget(const Widget::InitParams& params) OVERRIDE;
146 virtual NonClientFrameView* CreateNonClientFrameView() OVERRIDE;
147 virtual void UpdateFrameAfterFrameChange() OVERRIDE;
148 virtual bool ShouldUseNativeFrame() const OVERRIDE;
149 virtual void FrameTypeChanged() OVERRIDE;
150 virtual Widget* GetWidget() OVERRIDE;
151 virtual const Widget* GetWidget() const OVERRIDE;
152 virtual gfx::NativeView GetNativeView() const OVERRIDE;
153 virtual gfx::NativeWindow GetNativeWindow() const OVERRIDE;
154 virtual Widget* GetTopLevelWidget() OVERRIDE;
155 virtual const ui::Compositor* GetCompositor() const OVERRIDE;
156 virtual ui::Compositor* GetCompositor() OVERRIDE;
157 virtual void CalculateOffsetToAncestorWithLayer(
158 gfx::Point* offset,
159 ui::Layer** layer_parent) OVERRIDE;
160 virtual void ViewRemoved(View* view) OVERRIDE;
161 virtual void SetNativeWindowProperty(const char* name, void* value) OVERRIDE;
162 virtual void* GetNativeWindowProperty(const char* name) const OVERRIDE;
163 virtual TooltipManager* GetTooltipManager() const OVERRIDE;
164 virtual bool IsScreenReaderActive() const OVERRIDE;
165 virtual void SendNativeAccessibilityEvent(
166 View* view,
167 ui::AccessibilityTypes::Event event_type) OVERRIDE;
168 virtual void SetMouseCapture() OVERRIDE;
169 virtual void ReleaseMouseCapture() OVERRIDE;
170 virtual bool HasMouseCapture() const OVERRIDE;
171 virtual InputMethod* CreateInputMethod() OVERRIDE;
172 virtual void CenterWindow(const gfx::Size& size) OVERRIDE;
173 virtual void GetWindowPlacement(
174 gfx::Rect* bounds,
175 ui::WindowShowState* show_state) const OVERRIDE;
176 virtual void SetWindowTitle(const string16& title) OVERRIDE;
177 virtual void SetWindowIcons(const SkBitmap& window_icon,
178 const SkBitmap& app_icon) OVERRIDE;
179 virtual void SetAccessibleName(const string16& name) OVERRIDE;
180 virtual void SetAccessibleRole(ui::AccessibilityTypes::Role role) OVERRIDE;
181 virtual void SetAccessibleState(ui::AccessibilityTypes::State state) OVERRIDE;
182 virtual void InitModalType(ui::ModalType modal_type) OVERRIDE;
183 virtual gfx::Rect GetWindowScreenBounds() const OVERRIDE;
184 virtual gfx::Rect GetClientAreaScreenBounds() const OVERRIDE;
185 virtual gfx::Rect GetRestoredBounds() const OVERRIDE;
186 virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE;
187 virtual void SetSize(const gfx::Size& size) OVERRIDE;
188 virtual void StackAbove(gfx::NativeView native_view) OVERRIDE;
189 virtual void StackAtTop() OVERRIDE;
190 virtual void StackBelow(gfx::NativeView native_view) OVERRIDE;
191 virtual void SetShape(gfx::NativeRegion shape) OVERRIDE;
192 virtual void Close() OVERRIDE;
193 virtual void CloseNow() OVERRIDE;
194 virtual void Show() OVERRIDE;
195 virtual void Hide() OVERRIDE;
196 virtual void ShowMaximizedWithBounds(
197 const gfx::Rect& restored_bounds) OVERRIDE;
198 virtual void ShowWithWindowState(ui::WindowShowState window_state) OVERRIDE;
199 virtual bool IsVisible() const OVERRIDE;
200 virtual void Activate() OVERRIDE;
201 virtual void Deactivate() OVERRIDE;
202 virtual bool IsActive() const OVERRIDE;
203 virtual void SetAlwaysOnTop(bool always_on_top) OVERRIDE;
204 virtual void Maximize() OVERRIDE;
205 virtual void Minimize() OVERRIDE;
206 virtual bool IsMaximized() const OVERRIDE;
207 virtual bool IsMinimized() const OVERRIDE;
208 virtual void Restore() OVERRIDE;
209 virtual void SetFullscreen(bool fullscreen) OVERRIDE;
210 virtual bool IsFullscreen() const OVERRIDE;
211 virtual void SetOpacity(unsigned char opacity) OVERRIDE;
212 virtual void SetUseDragFrame(bool use_drag_frame) OVERRIDE;
213 virtual void FlashFrame(bool flash) OVERRIDE;
214 virtual bool IsAccessibleWidget() const OVERRIDE;
215 virtual void RunShellDrag(View* view,
216 const ui::OSExchangeData& data,
217 const gfx::Point& location,
218 int operation) OVERRIDE;
219 virtual void SchedulePaintInRect(const gfx::Rect& rect) OVERRIDE;
220 virtual void SetCursor(gfx::NativeCursor cursor) OVERRIDE;
221 virtual void ClearNativeFocus() OVERRIDE;
222 virtual void FocusNativeView(gfx::NativeView native_view) OVERRIDE;
223 virtual gfx::Rect GetWorkAreaBoundsInScreen() const OVERRIDE;
224 virtual void SetInactiveRenderingDisabled(bool value) OVERRIDE;
225 virtual Widget::MoveLoopResult RunMoveLoop() OVERRIDE;
226 virtual void EndMoveLoop() OVERRIDE;
227 virtual void SetVisibilityChangedAnimationsEnabled(bool value) OVERRIDE;
228
229 protected:
230 // Modifies event coordinates to the targeted widget contained by this widget.
231 template<class Event> GdkEvent* TransformEvent(Event* event) {
232 GdkWindow* dest = GTK_WIDGET(window_contents_)->window;
233 if (event && event->window != dest) {
234 gint dest_x, dest_y;
235 gdk_window_get_root_origin(dest, &dest_x, &dest_y);
236 event->x = event->x_root - dest_x;
237 event->y = event->y_root - dest_y;
238 }
239 return reinterpret_cast<GdkEvent*>(event);
240 }
241
242 // Event handlers:
243 CHROMEGTK_VIRTUAL_CALLBACK_1(NativeWidgetGtk, gboolean, OnButtonPress,
244 GdkEventButton*);
245 CHROMEGTK_VIRTUAL_CALLBACK_1(NativeWidgetGtk, void, OnSizeRequest,
246 GtkRequisition*);
247 CHROMEGTK_VIRTUAL_CALLBACK_1(NativeWidgetGtk, void, OnSizeAllocate,
248 GtkAllocation*);
249 CHROMEGTK_VIRTUAL_CALLBACK_1(NativeWidgetGtk, gboolean, OnPaint,
250 GdkEventExpose*);
251 CHROMEGTK_VIRTUAL_CALLBACK_4(NativeWidgetGtk, void, OnDragDataGet,
252 GdkDragContext*, GtkSelectionData*, guint,
253 guint);
254 CHROMEGTK_VIRTUAL_CALLBACK_6(NativeWidgetGtk, void, OnDragDataReceived,
255 GdkDragContext*, gint, gint, GtkSelectionData*,
256 guint, guint);
257 CHROMEGTK_VIRTUAL_CALLBACK_4(NativeWidgetGtk, gboolean, OnDragDrop,
258 GdkDragContext*, gint, gint, guint);
259 CHROMEGTK_VIRTUAL_CALLBACK_1(NativeWidgetGtk, void, OnDragEnd,
260 GdkDragContext*);
261 CHROMEGTK_VIRTUAL_CALLBACK_2(NativeWidgetGtk, gboolean, OnDragFailed,
262 GdkDragContext*, GtkDragResult);
263 CHROMEGTK_VIRTUAL_CALLBACK_2(NativeWidgetGtk, void, OnDragLeave,
264 GdkDragContext*, guint);
265 CHROMEGTK_VIRTUAL_CALLBACK_4(NativeWidgetGtk, gboolean, OnDragMotion,
266 GdkDragContext*, gint, gint, guint);
267 CHROMEGTK_VIRTUAL_CALLBACK_1(NativeWidgetGtk, gboolean, OnEnterNotify,
268 GdkEventCrossing*);
269 CHROMEGTK_VIRTUAL_CALLBACK_1(NativeWidgetGtk, gboolean, OnLeaveNotify,
270 GdkEventCrossing*);
271 CHROMEGTK_VIRTUAL_CALLBACK_1(NativeWidgetGtk, gboolean, OnMotionNotify,
272 GdkEventMotion*);
273 CHROMEGTK_VIRTUAL_CALLBACK_1(NativeWidgetGtk, gboolean, OnButtonRelease,
274 GdkEventButton*);
275 CHROMEGTK_VIRTUAL_CALLBACK_1(NativeWidgetGtk, gboolean, OnFocusIn,
276 GdkEventFocus*);
277 CHROMEGTK_VIRTUAL_CALLBACK_1(NativeWidgetGtk, gboolean, OnFocusOut,
278 GdkEventFocus*);
279 CHROMEGTK_VIRTUAL_CALLBACK_1(NativeWidgetGtk, gboolean, OnEventKey,
280 GdkEventKey*);
281 CHROMEGTK_VIRTUAL_CALLBACK_4(NativeWidgetGtk, gboolean, OnQueryTooltip, gint,
282 gint, gboolean, GtkTooltip*);
283 CHROMEGTK_VIRTUAL_CALLBACK_1(NativeWidgetGtk, gboolean, OnScroll,
284 GdkEventScroll*);
285 CHROMEGTK_VIRTUAL_CALLBACK_1(NativeWidgetGtk, gboolean, OnVisibilityNotify,
286 GdkEventVisibility*);
287 CHROMEGTK_VIRTUAL_CALLBACK_1(NativeWidgetGtk, gboolean, OnGrabBrokeEvent,
288 GdkEvent*);
289 CHROMEGTK_VIRTUAL_CALLBACK_1(NativeWidgetGtk, void, OnGrabNotify, gboolean);
290 CHROMEGTK_VIRTUAL_CALLBACK_0(NativeWidgetGtk, void, OnDestroy);
291 CHROMEGTK_VIRTUAL_CALLBACK_0(NativeWidgetGtk, void, OnShow);
292 CHROMEGTK_VIRTUAL_CALLBACK_0(NativeWidgetGtk, void, OnMap);
293 CHROMEGTK_VIRTUAL_CALLBACK_0(NativeWidgetGtk, void, OnHide);
294 CHROMEGTK_VIRTUAL_CALLBACK_1(NativeWidgetGtk, gboolean, OnWindowStateEvent,
295 GdkEventWindowState*);
296 CHROMEGTK_VIRTUAL_CALLBACK_1(NativeWidgetGtk, gboolean, OnConfigureEvent,
297 GdkEventConfigure*);
298
299 // Invoked when the widget is destroyed and right before the object
300 // destruction. Useful for overriding.
301 virtual void OnDestroyed(GObject *where_the_object_was);
302 static void OnDestroyedThunk(gpointer data, GObject *where_the_object_was) {
303 reinterpret_cast<NativeWidgetGtk*>(data)->OnDestroyed(where_the_object_was);
304 }
305
306 // Invoked when gtk grab is stolen by other GtkWidget in the same
307 // application.
308 virtual void HandleGtkGrabBroke();
309
310 const internal::NativeWidgetDelegate* delegate() const { return delegate_; }
311 internal::NativeWidgetDelegate* delegate() { return delegate_; }
312
313 private:
314 class DropObserver;
315 friend class DropObserver;
316
317 // Overridden from internal::InputMethodDelegate
318 virtual void DispatchKeyEventPostIME(const KeyEvent& key) OVERRIDE;
319
320 void SetInitParams(const Widget::InitParams& params);
321
322 // This is called only when the window is transparent.
323 CHROMEGTK_CALLBACK_1(NativeWidgetGtk, gboolean, OnWindowPaint,
324 GdkEventExpose*);
325
326 // Callbacks for expose event on child widgets. See the description of
327 // RegisterChildChildExposeHandler.
328 void OnChildExpose(GtkWidget* child);
329 static gboolean ChildExposeHandler(GtkWidget* widget, GdkEventExpose* event);
330
331 // Creates the GtkWidget.
332 void CreateGtkWidget(const Widget::InitParams& params);
333
334 // Invoked from create widget to enable the various bits needed for a
335 // transparent background. This is only invoked if MakeTransparent has been
336 // invoked.
337 void ConfigureWidgetForTransparentBackground(GtkWidget* parent);
338
339 // Invoked from create widget to enable the various bits needed for a
340 // window which doesn't receive events.
341 void ConfigureWidgetForIgnoreEvents();
342
343 // A utility function to draw a transparent background onto the |widget|.
344 static void DrawTransparentBackground(GtkWidget* widget,
345 GdkEventExpose* event);
346
347 // Asks the delegate if any to save the window's location and size.
348 void SaveWindowPosition();
349
350 // A delegate implementation that handles events received here.
351 // See class documentation for Widget in widget.h for a note about ownership.
352 internal::NativeWidgetDelegate* delegate_;
353
354 // Our native views. If we're a window/popup, then widget_ is the window and
355 // window_contents_ is a GtkFixed. If we're not a window/popup, then widget_
356 // and window_contents_ point to the same GtkFixed.
357 GtkWidget* widget_;
358 GtkWidget* window_contents_;
359
360 // Child GtkWidgets created with no parent need to be parented to a valid top
361 // level window otherwise Gtk throws a fit. |null_parent_| is an invisible
362 // popup that such GtkWidgets are parented to.
363 static GtkWidget* null_parent_;
364
365 // True if the widget is a child of some other widget.
366 bool child_;
367
368 // The TooltipManager.
369 // WARNING: RootView's destructor calls into the TooltipManager. As such, this
370 // must be destroyed AFTER root_view_.
371 scoped_ptr<TooltipManager> tooltip_manager_;
372
373 scoped_ptr<DropTargetGtk> drop_target_;
374
375 // The following factory is used to delay destruction.
376 base::WeakPtrFactory<NativeWidgetGtk> close_widget_factory_;
377
378 // See class documentation for Widget in widget.h for a note about ownership.
379 Widget::InitParams::Ownership ownership_;
380
381 // See description above make_transparent for details.
382 bool transparent_;
383
384 // Makes the window pass all events through to any windows behind it.
385 // Set during SetInitParams before the widget is created. The actual work of
386 // making the window ignore events is done by ConfigureWidgetForIgnoreEvents.
387 bool ignore_events_;
388
389 // See note in DropObserver for details on this.
390 bool ignore_drag_leave_;
391
392 unsigned char opacity_;
393
394 // This is non-null during the life of DoDrag and contains the actual data
395 // for the drag.
396 const OSExchangeDataProviderGtk* drag_data_;
397
398 // True to enable debug painting. Enabling causes the damaged
399 // region to be painted to flash in red.
400 static bool debug_paint_enabled_;
401
402 // State of the window, such as fullscreen, hidden...
403 GdkWindowState window_state_;
404
405 // Are we active?
406 bool is_active_;
407
408 // See make_transient_to_parent for a description.
409 bool transient_to_parent_;
410
411 // Last size supplied to OnSizeAllocate. We cache this as any time the
412 // size of a GtkWidget changes size_allocate is called, even if the size
413 // didn't change. If we didn't cache this and ignore calls when the size
414 // hasn't changed, we can end up getting stuck in a never ending loop.
415 gfx::Size size_;
416
417 // This is initially false and when the first focus-in event is received this
418 // is set to true and no additional processing is done. Subsequently when
419 // focus-in is received we do the normal focus manager processing.
420 //
421 // This behavior is necessitated by Gtk/X sending focus events
422 // asynchronously. The initial sequence for windows is typically: show,
423 // request focus on some widget. Because of async events on Gtk this becomes
424 // show, request focus, get focus in event which ends up clearing focus
425 // (first request to FocusManager::RestoreFocusedView ends up clearing focus).
426 bool got_initial_focus_in_;
427
428 // If true, we've received a focus-in event. If false we've received a
429 // focus-out event. We can get multiple focus-out events in a row, we use
430 // this to determine whether we should process the event.
431 bool has_focus_;
432
433 // If true, the window stays on top of the screen. This is only used
434 // for types other than TYPE_CHILD.
435 bool always_on_top_;
436
437 // If true, we enable the content widget's double buffering.
438 // This is false by default.
439 bool is_double_buffered_;
440
441 // Valid for the lifetime of StartDragForViewFromMouseEvent, indicates the
442 // view the drag started from.
443 View* dragged_view_;
444
445 // If the widget has ever been painted. This is used to guarantee
446 // that window manager shows the window only after the window is painted.
447 bool painted_;
448
449 // Have we done a pointer grab?
450 bool has_pointer_grab_;
451
452 // Have we done a keyboard grab?
453 bool has_keyboard_grab_;
454
455 // ID of the 'grab-notify' signal. If non-zero we're listening for
456 // 'grab-notify' events.
457 glong grab_notify_signal_id_;
458
459 // If we were created for a menu.
460 bool is_menu_;
461
462 scoped_ptr<ui::GtkSignalRegistrar> signal_registrar_;
463 scoped_ptr<ui::GtkSignalRegistrar> destroy_signal_registrar_;
464
465 DISALLOW_COPY_AND_ASSIGN(NativeWidgetGtk);
466 };
467
468 } // namespace views
469
470 #endif // UI_VIEWS_WIDGET_NATIVE_WIDGET_GTK_H_
OLDNEW
« no previous file with comments | « ui/views/widget/gtk_views_window.cc ('k') | ui/views/widget/native_widget_gtk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698