OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef CHROME_BROWSER_UI_GTK_APPS_NATIVE_APP_WINDOW_GTK_H_ | |
6 #define CHROME_BROWSER_UI_GTK_APPS_NATIVE_APP_WINDOW_GTK_H_ | |
7 | |
8 #include <gtk/gtk.h> | |
9 | |
10 #include "apps/app_window.h" | |
11 #include "apps/size_constraints.h" | |
12 #include "apps/ui/native_app_window.h" | |
13 #include "base/observer_list.h" | |
14 #include "base/timer/timer.h" | |
15 #include "chrome/browser/ui/gtk/extensions/extension_view_gtk.h" | |
16 #include "content/public/browser/web_contents_observer.h" | |
17 #include "third_party/skia/include/core/SkRegion.h" | |
18 #include "ui/base/gtk/gtk_signal.h" | |
19 #include "ui/base/x/active_window_watcher_x_observer.h" | |
20 #include "ui/gfx/rect.h" | |
21 #include "ui/gfx/x/x11_atom_cache.h" | |
22 | |
23 class ExtensionKeybindingRegistryGtk; | |
24 | |
25 namespace extensions { | |
26 class Extension; | |
27 } | |
28 | |
29 class NativeAppWindowGtk : public apps::NativeAppWindow, | |
30 public ExtensionViewGtk::Container, | |
31 public ui::ActiveWindowWatcherXObserver, | |
32 public content::WebContentsObserver { | |
33 public: | |
34 NativeAppWindowGtk(apps::AppWindow* app_window, | |
35 const apps::AppWindow::CreateParams& params); | |
36 | |
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; | |
59 | |
60 // ActiveWindowWatcherXObserver implementation. | |
61 virtual void ActiveWindowChanged(GdkWindow* active_window) OVERRIDE; | |
62 | |
63 // WebContentsObserver implementation. | |
64 virtual void RenderViewHostChanged( | |
65 content::RenderViewHost* old_host, | |
66 content::RenderViewHost* new_host) OVERRIDE; | |
67 | |
68 private: | |
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 UpdateBadgeIcon() OVERRIDE; | |
76 virtual void UpdateDraggableRegions( | |
77 const std::vector<extensions::DraggableRegion>& regions) OVERRIDE; | |
78 virtual SkRegion* GetDraggableRegion() OVERRIDE; | |
79 virtual void UpdateShape(scoped_ptr<SkRegion> region) OVERRIDE; | |
80 virtual void HandleKeyboardEvent( | |
81 const content::NativeWebKeyboardEvent& event) OVERRIDE; | |
82 virtual bool IsFrameless() const OVERRIDE; | |
83 virtual bool HasFrameColor() const OVERRIDE; | |
84 virtual SkColor FrameColor() const OVERRIDE; | |
85 virtual gfx::Insets GetFrameInsets() const OVERRIDE; | |
86 virtual void HideWithApp() OVERRIDE; | |
87 virtual void ShowWithApp() OVERRIDE; | |
88 virtual void UpdateShelfMenu() OVERRIDE; | |
89 virtual gfx::Size GetContentMinimumSize() const OVERRIDE; | |
90 virtual gfx::Size GetContentMaximumSize() const OVERRIDE; | |
91 virtual void SetContentSizeConstraints(const gfx::Size& min_size, | |
92 const gfx::Size& max_size) OVERRIDE; | |
93 | |
94 // web_modal::WebContentsModalDialogHost implementation. | |
95 virtual gfx::NativeView GetHostView() const OVERRIDE; | |
96 virtual gfx::Point GetDialogPosition(const gfx::Size& size) OVERRIDE; | |
97 virtual gfx::Size GetMaximumDialogSize() OVERRIDE; | |
98 virtual void AddObserver( | |
99 web_modal::ModalDialogHostObserver* observer) OVERRIDE; | |
100 virtual void RemoveObserver( | |
101 web_modal::ModalDialogHostObserver* observer) OVERRIDE; | |
102 | |
103 content::WebContents* web_contents() const { | |
104 return app_window_->web_contents(); | |
105 } | |
106 const extensions::Extension* extension() const { | |
107 return app_window_->extension(); | |
108 } | |
109 | |
110 virtual ~NativeAppWindowGtk(); | |
111 | |
112 // If the point (|x|, |y|) is within the resize border area of the window, | |
113 // returns true and sets |edge| to the appropriate GdkWindowEdge value. | |
114 // Otherwise, returns false. | |
115 bool GetWindowEdge(int x, int y, GdkWindowEdge* edge); | |
116 | |
117 CHROMEGTK_CALLBACK_1(NativeAppWindowGtk, gboolean, OnMainWindowDeleteEvent, | |
118 GdkEvent*); | |
119 CHROMEGTK_CALLBACK_1(NativeAppWindowGtk, gboolean, OnConfigure, | |
120 GdkEventConfigure*); | |
121 CHROMEGTK_CALLBACK_1(NativeAppWindowGtk, gboolean, OnWindowState, | |
122 GdkEventWindowState*); | |
123 CHROMEGTK_CALLBACK_1(NativeAppWindowGtk, gboolean, OnMouseMoveEvent, | |
124 GdkEventMotion*); | |
125 CHROMEGTK_CALLBACK_1(NativeAppWindowGtk, gboolean, OnButtonPress, | |
126 GdkEventButton*); | |
127 // Callback for PropertyChange XEvents. | |
128 CHROMEG_CALLBACK_1(NativeAppWindowGtk, GdkFilterReturn, | |
129 OnXEvent, GdkXEvent*, GdkEvent*); | |
130 | |
131 void OnConfigureDebounced(); | |
132 | |
133 void UpdateContentMinMaxSize(); | |
134 | |
135 apps::AppWindow* app_window_; // weak - AppWindow owns NativeAppWindow. | |
136 | |
137 GtkWindow* window_; | |
138 GdkWindowState state_; | |
139 | |
140 // True if the window manager thinks the window is active. Not all window | |
141 // managers keep track of this state (_NET_ACTIVE_WINDOW), in which case | |
142 // this will always be true. | |
143 bool is_active_; | |
144 | |
145 // The position and size of the current window. | |
146 gfx::Rect bounds_; | |
147 | |
148 // The position and size of the non-maximized, non-fullscreen window. | |
149 gfx::Rect restored_bounds_; | |
150 | |
151 // True if the RVH is in fullscreen mode. The window may not actually be in | |
152 // fullscreen, however: some WMs don't support fullscreen. | |
153 bool content_thinks_its_fullscreen_; | |
154 | |
155 // Represents whether the window is waiting to be maximized. | |
156 bool maximize_pending_; | |
157 | |
158 // The region is treated as title bar, can be dragged to move | |
159 // and double clicked to maximize. | |
160 scoped_ptr<SkRegion> draggable_region_; | |
161 | |
162 // If true, don't call gdk_window_raise() when we get a click in the title | |
163 // bar or window border. This is to work around a compiz bug. | |
164 bool suppress_window_raise_; | |
165 | |
166 // True if the window shows without frame. | |
167 bool frameless_; | |
168 | |
169 // True if the window should be resizable by the user. | |
170 bool resizable_; | |
171 | |
172 // True if the window should be kept on top of other windows that do not have | |
173 // this flag enabled. | |
174 bool always_on_top_; | |
175 | |
176 // The size constraints of the window. | |
177 apps::SizeConstraints size_constraints_; | |
178 | |
179 // The current window cursor. We set it to a resize cursor when over the | |
180 // custom frame border. We set it to NULL if we want the default cursor. | |
181 GdkCursor* frame_cursor_; | |
182 | |
183 // The timer used to save the window position for session restore. | |
184 base::OneShotTimer<NativeAppWindowGtk> window_configure_debounce_timer_; | |
185 | |
186 // The Extension Keybinding Registry responsible for registering listeners for | |
187 // accelerators that are sent to the window, that are destined to be turned | |
188 // into events and sent to the extension. | |
189 scoped_ptr<ExtensionKeybindingRegistryGtk> extension_keybinding_registry_; | |
190 | |
191 // Observers to be notified when any web contents modal dialog requires | |
192 // updating its dimensions. | |
193 ObserverList<web_modal::ModalDialogHostObserver> observer_list_; | |
194 | |
195 ui::X11AtomCache atom_cache_; | |
196 | |
197 // True if we listen for the XEvent. | |
198 bool is_x_event_listened_; | |
199 | |
200 DISALLOW_COPY_AND_ASSIGN(NativeAppWindowGtk); | |
201 }; | |
202 | |
203 #endif // CHROME_BROWSER_UI_GTK_APPS_NATIVE_APP_WINDOW_GTK_H_ | |
OLD | NEW |