| OLD | NEW |
| 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 23 matching lines...) Expand all Loading... |
| 34 class InputMethod; | 34 class InputMethod; |
| 35 class TooltipManagerGtk; | 35 class TooltipManagerGtk; |
| 36 class View; | 36 class View; |
| 37 class WindowGtk; | 37 class WindowGtk; |
| 38 | 38 |
| 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 NativeWidget, |
| 45 public NativeWidget, | |
| 46 public ui::ActiveWindowWatcherX::Observer, | 45 public ui::ActiveWindowWatcherX::Observer, |
| 47 public internal::InputMethodDelegate { | 46 public internal::InputMethodDelegate { |
| 48 public: | 47 public: |
| 49 WidgetGtk(); | 48 explicit WidgetGtk(internal::NativeWidgetDelegate* delegate); |
| 50 virtual ~WidgetGtk(); | 49 virtual ~WidgetGtk(); |
| 51 | 50 |
| 52 // Marks this window as transient to its parent. A window that is transient | |
| 53 // to its parent results in the parent rendering active when the child is | |
| 54 // active. | |
| 55 // This must be invoked before Init. This is only used for types other than | |
| 56 // TYPE_CHILD. The default is false. | |
| 57 // See gtk_window_set_transient_for for details. | |
| 58 void make_transient_to_parent() { | |
| 59 DCHECK(!widget_); | |
| 60 transient_to_parent_ = true; | |
| 61 } | |
| 62 | |
| 63 // Returns the transient parent. See make_transient_to_parent for details on | 51 // Returns the transient parent. See make_transient_to_parent for details on |
| 64 // what the transient parent is. | 52 // what the transient parent is. |
| 65 GtkWindow* GetTransientParent() const; | 53 GtkWindow* GetTransientParent() const; |
| 66 | 54 |
| 67 // Makes the background of the window totally transparent. This must be | 55 // Makes the background of the window totally transparent. This must be |
| 68 // invoked before Init. This does a couple of checks and returns true if | 56 // invoked before Init. This does a couple of checks and returns true if |
| 69 // the window can be made transparent. The actual work of making the window | 57 // the window can be made transparent. The actual work of making the window |
| 70 // transparent is done by ConfigureWidgetForTransparentBackground. | 58 // transparent is done by ConfigureWidgetForTransparentBackground. |
| 71 // This works for both child and window types. | 59 // This works for both child and window types. |
| 72 bool MakeTransparent(); | 60 bool MakeTransparent(); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 void ResetDropTarget(); | 104 void ResetDropTarget(); |
| 117 | 105 |
| 118 // Gets the requested size of the widget. This can be the size | 106 // Gets the requested size of the widget. This can be the size |
| 119 // stored in properties for a GtkViewsFixed, or in the requisitioned | 107 // stored in properties for a GtkViewsFixed, or in the requisitioned |
| 120 // size of other kinds of widgets. | 108 // size of other kinds of widgets. |
| 121 void GetRequestedSize(gfx::Size* out) const; | 109 void GetRequestedSize(gfx::Size* out) const; |
| 122 | 110 |
| 123 // Overridden from ui::ActiveWindowWatcherX::Observer. | 111 // Overridden from ui::ActiveWindowWatcherX::Observer. |
| 124 virtual void ActiveWindowChanged(GdkWindow* active_window); | 112 virtual void ActiveWindowChanged(GdkWindow* active_window); |
| 125 | 113 |
| 126 // Overridden from Widget: | |
| 127 virtual gfx::NativeView GetNativeView() const; | |
| 128 virtual gfx::NativeWindow GetNativeWindow() const; | |
| 129 virtual bool GetAccelerator(int cmd_id, ui::Accelerator* accelerator); | |
| 130 virtual Window* GetWindow(); | |
| 131 virtual const Window* GetWindow() const; | |
| 132 virtual void ViewHierarchyChanged(bool is_add, View *parent, | |
| 133 View *child); | |
| 134 virtual void NotifyAccessibilityEvent( | |
| 135 View* view, | |
| 136 ui::AccessibilityTypes::Event event_type, | |
| 137 bool send_native_event); | |
| 138 | |
| 139 // Clears the focus on the native widget having the focus. | 114 // Clears the focus on the native widget having the focus. |
| 140 virtual void ClearNativeFocus(); | 115 virtual void ClearNativeFocus(); |
| 141 | 116 |
| 142 // Handles a keyboard event by sending it to our focus manager. | 117 // Handles a keyboard event by sending it to our focus manager. |
| 143 // Returns true if it's handled by the focus manager. | 118 // Returns true if it's handled by the focus manager. |
| 144 bool HandleKeyboardEvent(const KeyEvent& key); | 119 bool HandleKeyboardEvent(const KeyEvent& key); |
| 145 | 120 |
| 146 // Enables debug painting. See |debug_paint_enabled_| for details. | 121 // Enables debug painting. See |debug_paint_enabled_| for details. |
| 147 static void EnableDebugPaint(); | 122 static void EnableDebugPaint(); |
| 148 | 123 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 161 // If you are adding a GtkWidget with its own GdkWindow that may | 136 // If you are adding a GtkWidget with its own GdkWindow that may |
| 162 // fill the entire area of the WidgetGtk to the view hierachy, you | 137 // fill the entire area of the WidgetGtk to the view hierachy, you |
| 163 // need use this function to tell WM that when the widget is ready | 138 // need use this function to tell WM that when the widget is ready |
| 164 // to be shown. | 139 // to be shown. |
| 165 // Caller of this method do not need to disconnect this because the | 140 // Caller of this method do not need to disconnect this because the |
| 166 // handler will be removed upon the first invocation of the handler, | 141 // handler will be removed upon the first invocation of the handler, |
| 167 // or when the widget is re-attached, and expose won't be emitted on | 142 // or when the widget is re-attached, and expose won't be emitted on |
| 168 // detached widget. | 143 // detached widget. |
| 169 static void RegisterChildExposeHandler(GtkWidget* widget); | 144 static void RegisterChildExposeHandler(GtkWidget* widget); |
| 170 | 145 |
| 146 void set_focus_on_creation(bool focus_on_creation) { |
| 147 focus_on_creation_ = focus_on_creation; |
| 148 } |
| 149 |
| 171 // Overridden from NativeWidget: | 150 // Overridden from NativeWidget: |
| 172 virtual void InitNativeWidget(const InitParams& params) OVERRIDE; | 151 virtual void InitNativeWidget(const Widget::InitParams& params) OVERRIDE; |
| 173 virtual Widget* GetWidget() OVERRIDE; | 152 virtual Widget* GetWidget() OVERRIDE; |
| 153 virtual const Widget* GetWidget() const OVERRIDE; |
| 154 virtual gfx::NativeView GetNativeView() const OVERRIDE; |
| 155 virtual gfx::NativeWindow GetNativeWindow() const OVERRIDE; |
| 156 virtual Window* GetContainingWindow() OVERRIDE; |
| 157 virtual const Window* GetContainingWindow() const OVERRIDE; |
| 158 virtual void ViewRemoved(View* view) OVERRIDE; |
| 174 virtual void SetNativeWindowProperty(const char* name, void* value) OVERRIDE; | 159 virtual void SetNativeWindowProperty(const char* name, void* value) OVERRIDE; |
| 175 virtual void* GetNativeWindowProperty(const char* name) OVERRIDE; | 160 virtual void* GetNativeWindowProperty(const char* name) OVERRIDE; |
| 176 virtual TooltipManager* GetTooltipManager() const OVERRIDE; | 161 virtual TooltipManager* GetTooltipManager() const OVERRIDE; |
| 177 virtual bool IsScreenReaderActive() const OVERRIDE; | 162 virtual bool IsScreenReaderActive() const OVERRIDE; |
| 163 virtual void SendNativeAccessibilityEvent( |
| 164 View* view, |
| 165 ui::AccessibilityTypes::Event event_type) OVERRIDE; |
| 178 virtual void SetMouseCapture() OVERRIDE; | 166 virtual void SetMouseCapture() OVERRIDE; |
| 179 virtual void ReleaseMouseCapture() OVERRIDE; | 167 virtual void ReleaseMouseCapture() OVERRIDE; |
| 180 virtual bool HasMouseCapture() const OVERRIDE; | 168 virtual bool HasMouseCapture() const OVERRIDE; |
| 169 virtual bool IsMouseButtonDown() const OVERRIDE; |
| 181 virtual InputMethod* GetInputMethodNative() OVERRIDE; | 170 virtual InputMethod* GetInputMethodNative() OVERRIDE; |
| 182 virtual void ReplaceInputMethod(InputMethod* input_method) OVERRIDE; | 171 virtual void ReplaceInputMethod(InputMethod* input_method) OVERRIDE; |
| 183 virtual gfx::Rect GetWindowScreenBounds() const OVERRIDE; | 172 virtual gfx::Rect GetWindowScreenBounds() const OVERRIDE; |
| 184 virtual gfx::Rect GetClientAreaScreenBounds() const OVERRIDE; | 173 virtual gfx::Rect GetClientAreaScreenBounds() const OVERRIDE; |
| 185 virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE; | 174 virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE; |
| 186 virtual void SetSize(const gfx::Size& size) OVERRIDE; | 175 virtual void SetSize(const gfx::Size& size) OVERRIDE; |
| 187 virtual void MoveAbove(gfx::NativeView native_view) OVERRIDE; | 176 virtual void MoveAbove(gfx::NativeView native_view) OVERRIDE; |
| 188 virtual void SetShape(gfx::NativeRegion shape) OVERRIDE; | 177 virtual void SetShape(gfx::NativeRegion shape) OVERRIDE; |
| 189 virtual void Close() OVERRIDE; | 178 virtual void Close() OVERRIDE; |
| 190 virtual void CloseNow() OVERRIDE; | 179 virtual void CloseNow() OVERRIDE; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 // when a window holding grab is closed without releasing grab. | 250 // when a window holding grab is closed without releasing grab. |
| 262 virtual void HandleXGrabBroke(); | 251 virtual void HandleXGrabBroke(); |
| 263 | 252 |
| 264 // Are we a subclass of WindowGtk? | 253 // Are we a subclass of WindowGtk? |
| 265 bool is_window_; | 254 bool is_window_; |
| 266 | 255 |
| 267 private: | 256 private: |
| 268 class DropObserver; | 257 class DropObserver; |
| 269 friend class DropObserver; | 258 friend class DropObserver; |
| 270 | 259 |
| 271 // Overridden from Widget | |
| 272 virtual RootView* CreateRootView() OVERRIDE; | |
| 273 | |
| 274 // Overridden from NativeWidget | 260 // Overridden from NativeWidget |
| 275 virtual gfx::AcceleratedWidget GetAcceleratedWidget() OVERRIDE; | 261 virtual gfx::AcceleratedWidget GetAcceleratedWidget() OVERRIDE; |
| 276 | 262 |
| 277 // Overridden from internal::InputMethodDelegate | 263 // Overridden from internal::InputMethodDelegate |
| 278 virtual void DispatchKeyEventPostIME(const KeyEvent& key) OVERRIDE; | 264 virtual void DispatchKeyEventPostIME(const KeyEvent& key) OVERRIDE; |
| 279 | 265 |
| 280 void SetInitParams(const InitParams& params); | 266 void SetInitParams(const Widget::InitParams& params); |
| 281 | 267 |
| 282 // This is called only when the window is transparent. | 268 // This is called only when the window is transparent. |
| 283 CHROMEGTK_CALLBACK_1(WidgetGtk, gboolean, OnWindowPaint, GdkEventExpose*); | 269 CHROMEGTK_CALLBACK_1(WidgetGtk, gboolean, OnWindowPaint, GdkEventExpose*); |
| 284 | 270 |
| 285 // Callbacks for expose event on child widgets. See the description of | 271 // Callbacks for expose event on child widgets. See the description of |
| 286 // RegisterChildChildExposeHandler. | 272 // RegisterChildChildExposeHandler. |
| 287 void OnChildExpose(GtkWidget* child); | 273 void OnChildExpose(GtkWidget* child); |
| 288 static gboolean ChildExposeHandler(GtkWidget* widget, GdkEventExpose* event); | 274 static gboolean ChildExposeHandler(GtkWidget* widget, GdkEventExpose* event); |
| 289 | 275 |
| 290 // Returns the first ancestor of |widget| that is a window. | 276 // Returns the first ancestor of |widget| that is a window. |
| 291 static Window* GetWindowImpl(GtkWidget* widget); | 277 static Window* GetWindowImpl(GtkWidget* widget); |
| 292 | 278 |
| 293 // Creates the GtkWidget. | 279 // Creates the GtkWidget. |
| 294 void CreateGtkWidget(const InitParams& params); | 280 void CreateGtkWidget(const Widget::InitParams& params); |
| 295 | 281 |
| 296 // Invoked from create widget to enable the various bits needed for a | 282 // Invoked from create widget to enable the various bits needed for a |
| 297 // transparent background. This is only invoked if MakeTransparent has been | 283 // transparent background. This is only invoked if MakeTransparent has been |
| 298 // invoked. | 284 // invoked. |
| 299 void ConfigureWidgetForTransparentBackground(GtkWidget* parent); | 285 void ConfigureWidgetForTransparentBackground(GtkWidget* parent); |
| 300 | 286 |
| 301 // Invoked from create widget to enable the various bits needed for a | 287 // Invoked from create widget to enable the various bits needed for a |
| 302 // window which doesn't receive events. | 288 // window which doesn't receive events. |
| 303 void ConfigureWidgetForIgnoreEvents(); | 289 void ConfigureWidgetForIgnoreEvents(); |
| 304 | 290 |
| 305 // A utility function to draw a transparent background onto the |widget|. | 291 // A utility function to draw a transparent background onto the |widget|. |
| 306 static void DrawTransparentBackground(GtkWidget* widget, | 292 static void DrawTransparentBackground(GtkWidget* widget, |
| 307 GdkEventExpose* event); | 293 GdkEventExpose* event); |
| 308 | 294 |
| 309 // A delegate implementation that handles events received here. | 295 // A delegate implementation that handles events received here. |
| 296 // See class documentation for Widget in widget.h for a note about ownership. |
| 310 internal::NativeWidgetDelegate* delegate_; | 297 internal::NativeWidgetDelegate* delegate_; |
| 311 | 298 |
| 312 // Our native views. If we're a window/popup, then widget_ is the window and | 299 // Our native views. If we're a window/popup, then widget_ is the window and |
| 313 // window_contents_ is a GtkFixed. If we're not a window/popup, then widget_ | 300 // window_contents_ is a GtkFixed. If we're not a window/popup, then widget_ |
| 314 // and window_contents_ point to the same GtkFixed. | 301 // and window_contents_ point to the same GtkFixed. |
| 315 GtkWidget* widget_; | 302 GtkWidget* widget_; |
| 316 GtkWidget* window_contents_; | 303 GtkWidget* window_contents_; |
| 317 | 304 |
| 318 // Child GtkWidgets created with no parent need to be parented to a valid top | 305 // Child GtkWidgets created with no parent need to be parented to a valid top |
| 319 // level window otherwise Gtk throws a fit. |null_parent_| is an invisible | 306 // level window otherwise Gtk throws a fit. |null_parent_| is an invisible |
| 320 // popup that such GtkWidgets are parented to. | 307 // popup that such GtkWidgets are parented to. |
| 321 static GtkWidget* null_parent_; | 308 static GtkWidget* null_parent_; |
| 322 | 309 |
| 323 // True if the widget is a child of some other widget. | 310 // True if the widget is a child of some other widget. |
| 324 bool child_; | 311 bool child_; |
| 325 | 312 |
| 326 // The TooltipManager. | 313 // The TooltipManager. |
| 327 // WARNING: RootView's destructor calls into the TooltipManager. As such, this | 314 // WARNING: RootView's destructor calls into the TooltipManager. As such, this |
| 328 // must be destroyed AFTER root_view_. | 315 // must be destroyed AFTER root_view_. |
| 329 scoped_ptr<TooltipManagerGtk> tooltip_manager_; | 316 scoped_ptr<TooltipManagerGtk> tooltip_manager_; |
| 330 | 317 |
| 331 scoped_ptr<DropTargetGtk> drop_target_; | 318 scoped_ptr<DropTargetGtk> drop_target_; |
| 332 | 319 |
| 333 // The following factory is used to delay destruction. | 320 // The following factory is used to delay destruction. |
| 334 ScopedRunnableMethodFactory<WidgetGtk> close_widget_factory_; | 321 ScopedRunnableMethodFactory<WidgetGtk> close_widget_factory_; |
| 335 | 322 |
| 336 // See description above setter. | 323 // See class documentation for Widget in widget.h for a note about ownership. |
| 337 bool delete_on_destroy_; | 324 bool delete_on_destroy_; |
| 338 | 325 |
| 339 // See description above make_transparent for details. | 326 // See description above make_transparent for details. |
| 340 bool transparent_; | 327 bool transparent_; |
| 341 | 328 |
| 342 // Makes the window pass all events through to any windows behind it. | 329 // Makes the window pass all events through to any windows behind it. |
| 343 // Set during SetInitParams before the widget is created. The actual work of | 330 // Set during SetInitParams before the widget is created. The actual work of |
| 344 // making the window ignore events is done by ConfigureWidgetForIgnoreEvents. | 331 // making the window ignore events is done by ConfigureWidgetForIgnoreEvents. |
| 345 bool ignore_events_; | 332 bool ignore_events_; |
| 346 | 333 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 // request focus on some widget. Because of async events on Gtk this becomes | 365 // request focus on some widget. Because of async events on Gtk this becomes |
| 379 // show, request focus, get focus in event which ends up clearing focus | 366 // show, request focus, get focus in event which ends up clearing focus |
| 380 // (first request to FocusManager::RestoreFocusedView ends up clearing focus). | 367 // (first request to FocusManager::RestoreFocusedView ends up clearing focus). |
| 381 bool got_initial_focus_in_; | 368 bool got_initial_focus_in_; |
| 382 | 369 |
| 383 // If true, we've received a focus-in event. If false we've received a | 370 // If true, we've received a focus-in event. If false we've received a |
| 384 // focus-out event. We can get multiple focus-out events in a row, we use | 371 // focus-out event. We can get multiple focus-out events in a row, we use |
| 385 // this to determine whether we should process the event. | 372 // this to determine whether we should process the event. |
| 386 bool has_focus_; | 373 bool has_focus_; |
| 387 | 374 |
| 375 // Whether we should SetFocus() on a newly created window after |
| 376 // Init(). Defaults to true. |
| 377 bool focus_on_creation_; |
| 378 |
| 388 // If true, the window stays on top of the screen. This is only used | 379 // If true, the window stays on top of the screen. This is only used |
| 389 // for types other than TYPE_CHILD. | 380 // for types other than TYPE_CHILD. |
| 390 bool always_on_top_; | 381 bool always_on_top_; |
| 391 | 382 |
| 392 // If true, we enable the content widget's double buffering. | 383 // If true, we enable the content widget's double buffering. |
| 393 // This is false by default. | 384 // This is false by default. |
| 394 bool is_double_buffered_; | 385 bool is_double_buffered_; |
| 395 | 386 |
| 396 // Indicates if we should handle the upcoming Alt key release event. | 387 // Indicates if we should handle the upcoming Alt key release event. |
| 397 bool should_handle_menu_key_release_; | 388 bool should_handle_menu_key_release_; |
| 398 | 389 |
| 399 // Valid for the lifetime of StartDragForViewFromMouseEvent, indicates the | 390 // Valid for the lifetime of StartDragForViewFromMouseEvent, indicates the |
| 400 // view the drag started from. | 391 // view the drag started from. |
| 401 View* dragged_view_; | 392 View* dragged_view_; |
| 402 | 393 |
| 403 // If the widget has ever been painted. This is used to guarantee | 394 // If the widget has ever been painted. This is used to guarantee |
| 404 // that window manager shows the window only after the window is painted. | 395 // that window manager shows the window only after the window is painted. |
| 405 bool painted_; | 396 bool painted_; |
| 406 | 397 |
| 407 scoped_ptr<InputMethod> input_method_; | 398 scoped_ptr<InputMethod> input_method_; |
| 408 | 399 |
| 409 DISALLOW_COPY_AND_ASSIGN(WidgetGtk); | 400 DISALLOW_COPY_AND_ASSIGN(WidgetGtk); |
| 410 }; | 401 }; |
| 411 | 402 |
| 412 } // namespace views | 403 } // namespace views |
| 413 | 404 |
| 414 #endif // VIEWS_WIDGET_WIDGET_GTK_H_ | 405 #endif // VIEWS_WIDGET_WIDGET_GTK_H_ |
| OLD | NEW |