1 // Copyright 2013 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.
5 #ifndef CHROME_BROWSER_UI_GTK_APPS_NATIVE_APP_WINDOW_GTK_H_
6 #define CHROME_BROWSER_UI_GTK_APPS_NATIVE_APP_WINDOW_GTK_H_
10 #include "apps/shell_window.h"
11 #include "apps/ui/native_app_window.h"
12 #include "base/observer_list.h"
13 #include "base/timer/timer.h"
14 #include "chrome/browser/ui/gtk/extensions/extension_view_gtk.h"
15 #include "content/public/browser/web_contents_observer.h"
16 #include "third_party/skia/include/core/SkRegion.h"
17 #include "ui/base/gtk/gtk_signal.h"
18 #include "ui/base/x/active_window_watcher_x_observer.h"
19 #include "ui/gfx/rect.h"
20 #include "ui/gfx/x/x11_atom_cache.h"
22 class ExtensionKeybindingRegistryGtk
;
25 namespace extensions
{
29 class NativeAppWindowGtk
: public apps::NativeAppWindow
,
30 public ExtensionViewGtk::Container
,
31 public ui::ActiveWindowWatcherXObserver
,
32 public content::WebContentsObserver
{
34 NativeAppWindowGtk(apps::ShellWindow
* shell_window
,
35 const apps::ShellWindow::CreateParams
& params
);
37 // ui::BaseWindow implementation.
38 virtual bool IsActive() const OVERRIDE
;
39 virtual bool IsMaximized() const OVERRIDE
;
40 virtual bool IsMinimized() const OVERRIDE
;
41 virtual bool IsFullscreen() const OVERRIDE
;
42 virtual gfx::NativeWindow
GetNativeWindow() OVERRIDE
;
43 virtual gfx::Rect
GetRestoredBounds() const OVERRIDE
;
44 virtual ui::WindowShowState
GetRestoredState() const OVERRIDE
;
45 virtual gfx::Rect
GetBounds() const OVERRIDE
;
46 virtual void Show() OVERRIDE
;
47 virtual void ShowInactive() OVERRIDE
;
48 virtual void Hide() OVERRIDE
;
49 virtual void Close() OVERRIDE
;
50 virtual void Activate() OVERRIDE
;
51 virtual void Deactivate() OVERRIDE
;
52 virtual void Maximize() OVERRIDE
;
53 virtual void Minimize() OVERRIDE
;
54 virtual void Restore() OVERRIDE
;
55 virtual void SetBounds(const gfx::Rect
& bounds
) OVERRIDE
;
56 virtual void FlashFrame(bool flash
) OVERRIDE
;
57 virtual bool IsAlwaysOnTop() const OVERRIDE
;
58 virtual void SetAlwaysOnTop(bool always_on_top
) OVERRIDE
;
60 // ActiveWindowWatcherXObserver implementation.
61 virtual void ActiveWindowChanged(GdkWindow
* active_window
) OVERRIDE
;
63 // WebContentsObserver implementation.
64 virtual void RenderViewHostChanged(
65 content::RenderViewHost
* old_host
,
66 content::RenderViewHost
* new_host
) OVERRIDE
;
69 // NativeAppWindow implementation.
70 virtual void SetFullscreen(int fullscreen_types
) OVERRIDE
;
71 virtual bool IsFullscreenOrPending() const OVERRIDE
;
72 virtual bool IsDetached() const OVERRIDE
;
73 virtual void UpdateWindowIcon() OVERRIDE
;
74 virtual void UpdateWindowTitle() OVERRIDE
;
75 virtual void UpdateDraggableRegions(
76 const std::vector
<extensions::DraggableRegion
>& regions
) OVERRIDE
;
77 virtual SkRegion
* GetDraggableRegion() OVERRIDE
;
78 virtual void UpdateShape(scoped_ptr
<SkRegion
> region
) OVERRIDE
;
79 virtual void HandleKeyboardEvent(
80 const content::NativeWebKeyboardEvent
& event
) OVERRIDE
;
81 virtual bool IsFrameless() const OVERRIDE
;
82 virtual gfx::Insets
GetFrameInsets() const OVERRIDE
;
83 virtual void HideWithApp() OVERRIDE
;
84 virtual void ShowWithApp() OVERRIDE
;
85 // Calls gtk_window_set_geometry_hints with the current size constraints.
86 virtual void UpdateWindowMinMaxSize() OVERRIDE
;
88 // web_modal::WebContentsModalDialogHost implementation.
89 virtual gfx::NativeView
GetHostView() const OVERRIDE
;
90 virtual gfx::Point
GetDialogPosition(const gfx::Size
& size
) OVERRIDE
;
91 virtual gfx::Size
GetMaximumDialogSize() OVERRIDE
;
92 virtual void AddObserver(
93 web_modal::ModalDialogHostObserver
* observer
) OVERRIDE
;
94 virtual void RemoveObserver(
95 web_modal::ModalDialogHostObserver
* observer
) OVERRIDE
;
97 content::WebContents
* web_contents() const {
98 return shell_window_
->web_contents();
100 const extensions::Extension
* extension() const {
101 return shell_window_
->extension();
104 virtual ~NativeAppWindowGtk();
106 // If the point (|x|, |y|) is within the resize border area of the window,
107 // returns true and sets |edge| to the appropriate GdkWindowEdge value.
108 // Otherwise, returns false.
109 bool GetWindowEdge(int x
, int y
, GdkWindowEdge
* edge
);
111 CHROMEGTK_CALLBACK_1(NativeAppWindowGtk
, gboolean
, OnMainWindowDeleteEvent
,
113 CHROMEGTK_CALLBACK_1(NativeAppWindowGtk
, gboolean
, OnConfigure
,
115 CHROMEGTK_CALLBACK_1(NativeAppWindowGtk
, gboolean
, OnWindowState
,
116 GdkEventWindowState
*);
117 CHROMEGTK_CALLBACK_1(NativeAppWindowGtk
, gboolean
, OnMouseMoveEvent
,
119 CHROMEGTK_CALLBACK_1(NativeAppWindowGtk
, gboolean
, OnButtonPress
,
121 // Callback for PropertyChange XEvents.
122 CHROMEG_CALLBACK_1(NativeAppWindowGtk
, GdkFilterReturn
,
123 OnXEvent
, GdkXEvent
*, GdkEvent
*);
125 void OnConfigureDebounced();
127 apps::ShellWindow
* shell_window_
; // weak - ShellWindow owns NativeAppWindow.
130 GdkWindowState state_
;
132 // True if the window manager thinks the window is active. Not all window
133 // managers keep track of this state (_NET_ACTIVE_WINDOW), in which case
134 // this will always be true.
137 // The position and size of the current window.
140 // The position and size of the non-maximized, non-fullscreen window.
141 gfx::Rect restored_bounds_
;
143 // True if the RVH is in fullscreen mode. The window may not actually be in
144 // fullscreen, however: some WMs don't support fullscreen.
145 bool content_thinks_its_fullscreen_
;
147 // Represents whether the window is waiting to be maximized.
148 bool maximize_pending_
;
150 // The region is treated as title bar, can be dragged to move
151 // and double clicked to maximize.
152 scoped_ptr
<SkRegion
> draggable_region_
;
154 // If true, don't call gdk_window_raise() when we get a click in the title
155 // bar or window border. This is to work around a compiz bug.
156 bool suppress_window_raise_
;
158 // True if the window shows without frame.
161 // True if the window should be resizable by the user.
164 // True if the window should be kept on top of other windows that do not have
165 // this flag enabled.
168 // The current window cursor. We set it to a resize cursor when over the
169 // custom frame border. We set it to NULL if we want the default cursor.
170 GdkCursor
* frame_cursor_
;
172 // The timer used to save the window position for session restore.
173 base::OneShotTimer
<NativeAppWindowGtk
> window_configure_debounce_timer_
;
175 // The Extension Keybinding Registry responsible for registering listeners for
176 // accelerators that are sent to the window, that are destined to be turned
177 // into events and sent to the extension.
178 scoped_ptr
<ExtensionKeybindingRegistryGtk
> extension_keybinding_registry_
;
180 // Observers to be notified when any web contents modal dialog requires
181 // updating its dimensions.
182 ObserverList
<web_modal::ModalDialogHostObserver
> observer_list_
;
184 ui::X11AtomCache atom_cache_
;
186 // True if we listen for the XEvent.
187 bool is_x_event_listened_
;
189 DISALLOW_COPY_AND_ASSIGN(NativeAppWindowGtk
);
192 #endif // CHROME_BROWSER_UI_GTK_APPS_NATIVE_APP_WINDOW_GTK_H_