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

Side by Side Diff: views/widget/widget_gtk.h

Issue 6881107: Rework the way Widget::Init works: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 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
« no previous file with comments | « views/widget/widget.cc ('k') | views/widget/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
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef VIEWS_WIDGET_WIDGET_GTK_H_ 5 #ifndef VIEWS_WIDGET_WIDGET_GTK_H_
6 #define VIEWS_WIDGET_WIDGET_GTK_H_ 6 #define VIEWS_WIDGET_WIDGET_GTK_H_
7 #pragma once 7 #pragma once
8 8
9 #include <gtk/gtk.h> 9 #include <gtk/gtk.h>
10 10
(...skipping 28 matching lines...) Expand all
39 namespace internal { 39 namespace internal {
40 class NativeWidgetDelegate; 40 class NativeWidgetDelegate;
41 } 41 }
42 42
43 // Widget implementation for GTK. 43 // Widget implementation for GTK.
44 class WidgetGtk : public Widget, 44 class WidgetGtk : public Widget,
45 public NativeWidget, 45 public NativeWidget,
46 public ui::ActiveWindowWatcherX::Observer, 46 public ui::ActiveWindowWatcherX::Observer,
47 public internal::InputMethodDelegate { 47 public internal::InputMethodDelegate {
48 public: 48 public:
49 // Type of widget. 49 WidgetGtk();
50 enum Type {
51 // Used for popup type windows (bubbles, menus ...).
52 // NOTE: on X windows of this type can NOT get focus. If you need a popup
53 // like widget that can be focused use TYPE_WINDOW and set the window type
54 // to WINDOW_TYPE_CHROME_INFO_BUBBLE.
55 TYPE_POPUP,
56
57 // A top level window with no title or control buttons.
58 // NOTE: On ChromeOS TYPE_WINDOW and TYPE_DECORATED_WINDOW behave the same.
59 TYPE_WINDOW,
60
61 // A top level, decorated window.
62 // NOTE: On ChromeOS TYPE_WINDOW and TYPE_DECORATED_WINDOW behave the same.
63 TYPE_DECORATED_WINDOW,
64
65 // A child widget.
66 TYPE_CHILD
67 };
68
69 explicit WidgetGtk(Type type);
70 virtual ~WidgetGtk(); 50 virtual ~WidgetGtk();
71 51
72 // Marks this window as transient to its parent. A window that is transient 52 // Marks this window as transient to its parent. A window that is transient
73 // to its parent results in the parent rendering active when the child is 53 // to its parent results in the parent rendering active when the child is
74 // active. 54 // active.
75 // This must be invoked before Init. This is only used for types other than 55 // This must be invoked before Init. This is only used for types other than
76 // TYPE_CHILD. The default is false. 56 // TYPE_CHILD. The default is false.
77 // See gtk_window_set_transient_for for details. 57 // See gtk_window_set_transient_for for details.
78 void make_transient_to_parent() { 58 void make_transient_to_parent() {
79 DCHECK(!widget_); 59 DCHECK(!widget_);
(...skipping 11 matching lines...) Expand all
91 // This works for both child and window types. 71 // This works for both child and window types.
92 bool MakeTransparent(); 72 bool MakeTransparent();
93 bool is_transparent() const { return transparent_; } 73 bool is_transparent() const { return transparent_; }
94 74
95 // Enable/Disable double buffering.This is neccessary to prevent 75 // Enable/Disable double buffering.This is neccessary to prevent
96 // flickering in ScrollView, which has both native and view 76 // flickering in ScrollView, which has both native and view
97 // controls. 77 // controls.
98 void EnableDoubleBuffer(bool enabled); 78 void EnableDoubleBuffer(bool enabled);
99 bool is_double_buffered() const { return is_double_buffered_; } 79 bool is_double_buffered() const { return is_double_buffered_; }
100 80
101 // Makes the window pass all events through to any windows behind it.
102 // This must be invoked before Init. This does a couple of checks and returns
103 // true if the window can be made to ignore events. The actual work of making
104 // the window ignore events is done by ConfigureWidgetForIgnoreEvents.
105 bool MakeIgnoreEvents();
106 bool is_ignore_events() const { return ignore_events_; } 81 bool is_ignore_events() const { return ignore_events_; }
107 82
108 // Sets whether or not we are deleted when the widget is destroyed. The
109 // default is true.
110 void set_delete_on_destroy(bool delete_on_destroy) {
111 delete_on_destroy_ = delete_on_destroy;
112 }
113
114 // Adds and removes the specified widget as a child of this widget's contents. 83 // Adds and removes the specified widget as a child of this widget's contents.
115 // These methods make sure to add the widget to the window's contents 84 // These methods make sure to add the widget to the window's contents
116 // container if this widget is a window. 85 // container if this widget is a window.
117 void AddChild(GtkWidget* child); 86 void AddChild(GtkWidget* child);
118 void RemoveChild(GtkWidget* child); 87 void RemoveChild(GtkWidget* child);
119 88
120 // A safe way to reparent a child widget to this widget. Calls 89 // A safe way to reparent a child widget to this widget. Calls
121 // gtk_widget_reparent which handles refcounting to avoid destroying the 90 // gtk_widget_reparent which handles refcounting to avoid destroying the
122 // widget when removing it from its old parent. 91 // widget when removing it from its old parent.
123 void ReparentChild(GtkWidget* child); 92 void ReparentChild(GtkWidget* child);
(...skipping 24 matching lines...) Expand all
148 117
149 // Gets the requested size of the widget. This can be the size 118 // Gets the requested size of the widget. This can be the size
150 // stored in properties for a GtkViewsFixed, or in the requisitioned 119 // stored in properties for a GtkViewsFixed, or in the requisitioned
151 // size of other kinds of widgets. 120 // size of other kinds of widgets.
152 void GetRequestedSize(gfx::Size* out) const; 121 void GetRequestedSize(gfx::Size* out) const;
153 122
154 // Overridden from ui::ActiveWindowWatcherX::Observer. 123 // Overridden from ui::ActiveWindowWatcherX::Observer.
155 virtual void ActiveWindowChanged(GdkWindow* active_window); 124 virtual void ActiveWindowChanged(GdkWindow* active_window);
156 125
157 // Overridden from Widget: 126 // Overridden from Widget:
158 virtual void Init(gfx::NativeView parent, const gfx::Rect& bounds);
159 virtual void InitWithWidget(Widget* parent, const gfx::Rect& bounds);
160 virtual gfx::NativeView GetNativeView() const; 127 virtual gfx::NativeView GetNativeView() const;
161 virtual bool GetAccelerator(int cmd_id, ui::Accelerator* accelerator); 128 virtual bool GetAccelerator(int cmd_id, ui::Accelerator* accelerator);
162 virtual Window* GetWindow(); 129 virtual Window* GetWindow();
163 virtual const Window* GetWindow() const; 130 virtual const Window* GetWindow() const;
164 virtual void ViewHierarchyChanged(bool is_add, View *parent, 131 virtual void ViewHierarchyChanged(bool is_add, View *parent,
165 View *child); 132 View *child);
166 virtual void NotifyAccessibilityEvent( 133 virtual void NotifyAccessibilityEvent(
167 View* view, 134 View* view,
168 ui::AccessibilityTypes::Event event_type, 135 ui::AccessibilityTypes::Event event_type,
169 bool send_native_event); 136 bool send_native_event);
(...skipping 24 matching lines...) Expand all
194 // fill the entire area of the WidgetGtk to the view hierachy, you 161 // fill the entire area of the WidgetGtk to the view hierachy, you
195 // need use this function to tell WM that when the widget is ready 162 // need use this function to tell WM that when the widget is ready
196 // to be shown. 163 // to be shown.
197 // Caller of this method do not need to disconnect this because the 164 // Caller of this method do not need to disconnect this because the
198 // handler will be removed upon the first invocation of the handler, 165 // handler will be removed upon the first invocation of the handler,
199 // or when the widget is re-attached, and expose won't be emitted on 166 // or when the widget is re-attached, and expose won't be emitted on
200 // detached widget. 167 // detached widget.
201 static void RegisterChildExposeHandler(GtkWidget* widget); 168 static void RegisterChildExposeHandler(GtkWidget* widget);
202 169
203 // Overridden from NativeWidget: 170 // Overridden from NativeWidget:
204 virtual void SetCreateParams(const CreateParams& params) OVERRIDE; 171 virtual void InitNativeWidget(const CreateParams& params) OVERRIDE;
205 virtual Widget* GetWidget() OVERRIDE; 172 virtual Widget* GetWidget() OVERRIDE;
206 virtual void SetNativeWindowProperty(const char* name, void* value) OVERRIDE; 173 virtual void SetNativeWindowProperty(const char* name, void* value) OVERRIDE;
207 virtual void* GetNativeWindowProperty(const char* name) OVERRIDE; 174 virtual void* GetNativeWindowProperty(const char* name) OVERRIDE;
208 virtual TooltipManager* GetTooltipManager() const OVERRIDE; 175 virtual TooltipManager* GetTooltipManager() const OVERRIDE;
209 virtual bool IsScreenReaderActive() const OVERRIDE; 176 virtual bool IsScreenReaderActive() const OVERRIDE;
210 virtual void SetMouseCapture() OVERRIDE; 177 virtual void SetMouseCapture() OVERRIDE;
211 virtual void ReleaseMouseCapture() OVERRIDE; 178 virtual void ReleaseMouseCapture() OVERRIDE;
212 virtual bool HasMouseCapture() const OVERRIDE; 179 virtual bool HasMouseCapture() const OVERRIDE;
213 virtual InputMethod* GetInputMethodNative() OVERRIDE; 180 virtual InputMethod* GetInputMethodNative() OVERRIDE;
214 virtual void ReplaceInputMethod(InputMethod* input_method) OVERRIDE; 181 virtual void ReplaceInputMethod(InputMethod* input_method) OVERRIDE;
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 269
303 // Overridden from Widget 270 // Overridden from Widget
304 virtual RootView* CreateRootView() OVERRIDE; 271 virtual RootView* CreateRootView() OVERRIDE;
305 272
306 // Overridden from NativeWidget 273 // Overridden from NativeWidget
307 virtual gfx::AcceleratedWidget GetAcceleratedWidget() OVERRIDE; 274 virtual gfx::AcceleratedWidget GetAcceleratedWidget() OVERRIDE;
308 275
309 // Overridden from internal::InputMethodDelegate 276 // Overridden from internal::InputMethodDelegate
310 virtual void DispatchKeyEventPostIME(const KeyEvent& key) OVERRIDE; 277 virtual void DispatchKeyEventPostIME(const KeyEvent& key) OVERRIDE;
311 278
279 void SetCreateParams(const CreateParams& params);
280
312 // This is called only when the window is transparent. 281 // This is called only when the window is transparent.
313 CHROMEGTK_CALLBACK_1(WidgetGtk, gboolean, OnWindowPaint, GdkEventExpose*); 282 CHROMEGTK_CALLBACK_1(WidgetGtk, gboolean, OnWindowPaint, GdkEventExpose*);
314 283
315 // Callbacks for expose event on child widgets. See the description of 284 // Callbacks for expose event on child widgets. See the description of
316 // RegisterChildChildExposeHandler. 285 // RegisterChildChildExposeHandler.
317 void OnChildExpose(GtkWidget* child); 286 void OnChildExpose(GtkWidget* child);
318 static gboolean ChildExposeHandler(GtkWidget* widget, GdkEventExpose* event); 287 static gboolean ChildExposeHandler(GtkWidget* widget, GdkEventExpose* event);
319 288
320 // Returns the first ancestor of |widget| that is a window. 289 // Returns the first ancestor of |widget| that is a window.
321 static Window* GetWindowImpl(GtkWidget* widget); 290 static Window* GetWindowImpl(GtkWidget* widget);
322 291
323 // Creates the GtkWidget. 292 // Creates the GtkWidget.
324 void CreateGtkWidget(GtkWidget* parent, const gfx::Rect& bounds); 293 void CreateGtkWidget(const CreateParams& params);
325 294
326 // Invoked from create widget to enable the various bits needed for a 295 // Invoked from create widget to enable the various bits needed for a
327 // transparent background. This is only invoked if MakeTransparent has been 296 // transparent background. This is only invoked if MakeTransparent has been
328 // invoked. 297 // invoked.
329 void ConfigureWidgetForTransparentBackground(GtkWidget* parent); 298 void ConfigureWidgetForTransparentBackground(GtkWidget* parent);
330 299
331 // Invoked from create widget to enable the various bits needed for a 300 // Invoked from create widget to enable the various bits needed for a
332 // window which doesn't receive events. This is only invoked if 301 // window which doesn't receive events.
333 // MakeIgnoreEvents has been invoked.
334 void ConfigureWidgetForIgnoreEvents(); 302 void ConfigureWidgetForIgnoreEvents();
335 303
336 // A utility function to draw a transparent background onto the |widget|. 304 // A utility function to draw a transparent background onto the |widget|.
337 static void DrawTransparentBackground(GtkWidget* widget, 305 static void DrawTransparentBackground(GtkWidget* widget,
338 GdkEventExpose* event); 306 GdkEventExpose* event);
339 307
340 // A delegate implementation that handles events received here. 308 // A delegate implementation that handles events received here.
341 internal::NativeWidgetDelegate* delegate_; 309 internal::NativeWidgetDelegate* delegate_;
342 310
343 const Type type_;
344
345 // Our native views. If we're a window/popup, then widget_ is the window and 311 // Our native views. If we're a window/popup, then widget_ is the window and
346 // window_contents_ is a GtkFixed. If we're not a window/popup, then widget_ 312 // window_contents_ is a GtkFixed. If we're not a window/popup, then widget_
347 // and window_contents_ point to the same GtkFixed. 313 // and window_contents_ point to the same GtkFixed.
348 GtkWidget* widget_; 314 GtkWidget* widget_;
349 GtkWidget* window_contents_; 315 GtkWidget* window_contents_;
350 316
351 // Child GtkWidgets created with no parent need to be parented to a valid top 317 // Child GtkWidgets created with no parent need to be parented to a valid top
352 // level window otherwise Gtk throws a fit. |null_parent_| is an invisible 318 // level window otherwise Gtk throws a fit. |null_parent_| is an invisible
353 // popup that such GtkWidgets are parented to. 319 // popup that such GtkWidgets are parented to.
354 static GtkWidget* null_parent_; 320 static GtkWidget* null_parent_;
355 321
322 // True if the widget is a child of some other widget.
323 bool child_;
324
356 // The TooltipManager. 325 // The TooltipManager.
357 // WARNING: RootView's destructor calls into the TooltipManager. As such, this 326 // WARNING: RootView's destructor calls into the TooltipManager. As such, this
358 // must be destroyed AFTER root_view_. 327 // must be destroyed AFTER root_view_.
359 scoped_ptr<TooltipManagerGtk> tooltip_manager_; 328 scoped_ptr<TooltipManagerGtk> tooltip_manager_;
360 329
361 scoped_ptr<DropTargetGtk> drop_target_; 330 scoped_ptr<DropTargetGtk> drop_target_;
362 331
363 // The following factory is used to delay destruction. 332 // The following factory is used to delay destruction.
364 ScopedRunnableMethodFactory<WidgetGtk> close_widget_factory_; 333 ScopedRunnableMethodFactory<WidgetGtk> close_widget_factory_;
365 334
366 // See description above setter. 335 // See description above setter.
367 bool delete_on_destroy_; 336 bool delete_on_destroy_;
368 337
369 // See description above make_transparent for details. 338 // See description above make_transparent for details.
370 bool transparent_; 339 bool transparent_;
371 340
372 // See description above MakeIgnoreEvents for details. 341 // Makes the window pass all events through to any windows behind it.
342 // Set during SetCreateParams before the widget is created. The actual work of
343 // making the window ignore events is done by ConfigureWidgetForIgnoreEvents.
373 bool ignore_events_; 344 bool ignore_events_;
374 345
375 // See note in DropObserver for details on this. 346 // See note in DropObserver for details on this.
376 bool ignore_drag_leave_; 347 bool ignore_drag_leave_;
377 348
378 unsigned char opacity_; 349 unsigned char opacity_;
379 350
380 // This is non-null during the life of DoDrag and contains the actual data 351 // This is non-null during the life of DoDrag and contains the actual data
381 // for the drag. 352 // for the drag.
382 const OSExchangeDataProviderGtk* drag_data_; 353 const OSExchangeDataProviderGtk* drag_data_;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 bool painted_; 404 bool painted_;
434 405
435 scoped_ptr<InputMethod> input_method_; 406 scoped_ptr<InputMethod> input_method_;
436 407
437 DISALLOW_COPY_AND_ASSIGN(WidgetGtk); 408 DISALLOW_COPY_AND_ASSIGN(WidgetGtk);
438 }; 409 };
439 410
440 } // namespace views 411 } // namespace views
441 412
442 #endif // VIEWS_WIDGET_WIDGET_GTK_H_ 413 #endif // VIEWS_WIDGET_WIDGET_GTK_H_
OLDNEW
« no previous file with comments | « views/widget/widget.cc ('k') | views/widget/widget_gtk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698