OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 #include "chrome/browser/ui/views/apps/native_app_window_views.h" | 5 #include "apps/ui/views/base_native_app_window_views.h" |
6 | 6 |
7 #include "apps/app_window.h" | 7 #include "apps/app_window.h" |
8 #include "apps/ui/views/app_window_frame_view.h" | |
9 #include "base/command_line.h" | |
10 #include "base/threading/sequenced_worker_pool.h" | 8 #include "base/threading/sequenced_worker_pool.h" |
11 #include "chrome/app/chrome_command_ids.h" | |
12 #include "chrome/browser/app_mode/app_mode_utils.h" | |
13 #include "chrome/browser/chrome_page_zoom.h" | |
14 #include "chrome/browser/extensions/extension_host.h" | |
15 #include "chrome/browser/favicon/favicon_tab_helper.h" | |
16 #include "chrome/browser/profiles/profile.h" | |
17 #include "chrome/browser/ui/ash/multi_user/multi_user_context_menu.h" | |
18 #include "chrome/browser/ui/host_desktop.h" | |
19 #include "chrome/browser/ui/views/apps/shaped_app_window_targeter.h" | |
20 #include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views
.h" | |
21 #include "chrome/browser/ui/views/frame/taskbar_decorator.h" | |
22 #include "chrome/browser/web_applications/web_app.h" | |
23 #include "chrome/common/chrome_switches.h" | |
24 #include "content/public/browser/browser_thread.h" | |
25 #include "content/public/browser/render_view_host.h" | 9 #include "content/public/browser/render_view_host.h" |
26 #include "content/public/browser/render_widget_host_view.h" | 10 #include "content/public/browser/render_widget_host_view.h" |
27 #include "content/public/browser/web_contents.h" | 11 #include "content/public/browser/web_contents.h" |
28 #include "content/public/browser/web_contents_view.h" | 12 #include "content/public/browser/web_contents_view.h" |
29 #include "extensions/common/draggable_region.h" | 13 #include "extensions/common/draggable_region.h" |
30 #include "extensions/common/extension.h" | 14 #include "third_party/skia/include/core/SkRegion.h" |
31 #include "ui/base/hit_test.h" | 15 #include "ui/gfx/path.h" |
32 #include "ui/base/models/simple_menu_model.h" | |
33 #include "ui/views/controls/menu/menu_runner.h" | |
34 #include "ui/views/controls/webview/webview.h" | 16 #include "ui/views/controls/webview/webview.h" |
35 #include "ui/views/widget/widget.h" | 17 #include "ui/views/widget/widget.h" |
36 #include "ui/views/window/non_client_view.h" | 18 #include "ui/views/window/non_client_view.h" |
37 #include "ui/wm/public/easy_resize_window_targeter.h" | |
38 | |
39 #if defined(OS_LINUX) | |
40 #include "chrome/browser/shell_integration_linux.h" | |
41 #endif | |
42 | |
43 #if defined(USE_ASH) | |
44 #include "ash/ash_constants.h" | |
45 #include "ash/ash_switches.h" | |
46 #include "ash/screen_util.h" | |
47 #include "ash/shell.h" | |
48 #include "ash/wm/custom_frame_view_ash.h" | |
49 #include "ash/wm/immersive_fullscreen_controller.h" | |
50 #include "ash/wm/panels/panel_frame_view.h" | |
51 #include "ash/wm/window_state.h" | |
52 #include "ash/wm/window_state_delegate.h" | |
53 #include "ash/wm/window_state_observer.h" | |
54 #include "chrome/browser/ui/ash/ash_util.h" | |
55 #include "ui/aura/client/aura_constants.h" | |
56 #include "ui/aura/client/window_tree_client.h" | |
57 #include "ui/aura/window.h" | |
58 #include "ui/aura/window_observer.h" | |
59 #endif | |
60 | 19 |
61 #if defined(USE_AURA) | 20 #if defined(USE_AURA) |
62 #include "ui/aura/window.h" | 21 #include "ui/aura/window.h" |
63 #endif | 22 #endif |
64 | 23 |
65 using apps::AppWindow; | 24 using apps::AppWindow; |
66 | 25 |
67 namespace { | 26 BaseNativeAppWindowViews::BaseNativeAppWindowViews() |
| 27 : app_window_(NULL), |
| 28 web_view_(NULL), |
| 29 window_(NULL), |
| 30 frameless_(false), |
| 31 transparent_background_(false), |
| 32 resizable_(false) {} |
68 | 33 |
69 const int kMinPanelWidth = 100; | 34 void BaseNativeAppWindowViews::Init( |
70 const int kMinPanelHeight = 100; | 35 apps::AppWindow* app_window, |
71 const int kDefaultPanelWidth = 200; | 36 const AppWindow::CreateParams& create_params) { |
72 const int kDefaultPanelHeight = 300; | |
73 const int kResizeInsideBoundsSize = 5; | |
74 const int kResizeAreaCornerSize = 16; | |
75 | |
76 struct AcceleratorMapping { | |
77 ui::KeyboardCode keycode; | |
78 int modifiers; | |
79 int command_id; | |
80 }; | |
81 | |
82 const AcceleratorMapping kAppWindowAcceleratorMap[] = { | |
83 { ui::VKEY_W, ui::EF_CONTROL_DOWN, IDC_CLOSE_WINDOW }, | |
84 { ui::VKEY_W, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN, IDC_CLOSE_WINDOW }, | |
85 { ui::VKEY_F4, ui::EF_ALT_DOWN, IDC_CLOSE_WINDOW }, | |
86 }; | |
87 | |
88 // These accelerators will only be available in kiosk mode. These allow the | |
89 // user to manually zoom app windows. This is only necessary in kiosk mode | |
90 // (in normal mode, the user can zoom via the screen magnifier). | |
91 // TODO(xiyuan): Write a test for kiosk accelerators. | |
92 const AcceleratorMapping kAppWindowKioskAppModeAcceleratorMap[] = { | |
93 { ui::VKEY_OEM_MINUS, ui::EF_CONTROL_DOWN, IDC_ZOOM_MINUS }, | |
94 { ui::VKEY_OEM_MINUS, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN, | |
95 IDC_ZOOM_MINUS }, | |
96 { ui::VKEY_SUBTRACT, ui::EF_CONTROL_DOWN, IDC_ZOOM_MINUS }, | |
97 { ui::VKEY_OEM_PLUS, ui::EF_CONTROL_DOWN, IDC_ZOOM_PLUS }, | |
98 { ui::VKEY_OEM_PLUS, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN, IDC_ZOOM_PLUS }, | |
99 { ui::VKEY_ADD, ui::EF_CONTROL_DOWN, IDC_ZOOM_PLUS }, | |
100 { ui::VKEY_0, ui::EF_CONTROL_DOWN, IDC_ZOOM_NORMAL }, | |
101 { ui::VKEY_NUMPAD0, ui::EF_CONTROL_DOWN, IDC_ZOOM_NORMAL }, | |
102 }; | |
103 | |
104 void AddAcceleratorsFromMapping(const AcceleratorMapping mapping[], | |
105 size_t mapping_length, | |
106 std::map<ui::Accelerator, int>* accelerators) { | |
107 for (size_t i = 0; i < mapping_length; ++i) { | |
108 ui::Accelerator accelerator(mapping[i].keycode, mapping[i].modifiers); | |
109 (*accelerators)[accelerator] = mapping[i].command_id; | |
110 } | |
111 } | |
112 | |
113 const std::map<ui::Accelerator, int>& GetAcceleratorTable() { | |
114 typedef std::map<ui::Accelerator, int> AcceleratorMap; | |
115 CR_DEFINE_STATIC_LOCAL(AcceleratorMap, accelerators, ()); | |
116 if (accelerators.empty()) { | |
117 AddAcceleratorsFromMapping( | |
118 kAppWindowAcceleratorMap, | |
119 arraysize(kAppWindowAcceleratorMap), | |
120 &accelerators); | |
121 | |
122 // Add accelerators for kiosk mode. | |
123 if (chrome::IsRunningInForcedAppMode()) { | |
124 AddAcceleratorsFromMapping( | |
125 kAppWindowKioskAppModeAcceleratorMap, | |
126 arraysize(kAppWindowKioskAppModeAcceleratorMap), | |
127 &accelerators); | |
128 } | |
129 } | |
130 return accelerators; | |
131 } | |
132 | |
133 #if defined(USE_ASH) | |
134 // This class handles a user's fullscreen request (Shift+F4/F4). | |
135 class NativeAppWindowStateDelegate : public ash::wm::WindowStateDelegate, | |
136 public ash::wm::WindowStateObserver, | |
137 public aura::WindowObserver { | |
138 public: | |
139 NativeAppWindowStateDelegate(AppWindow* app_window, | |
140 apps::NativeAppWindow* native_app_window) | |
141 : app_window_(app_window), | |
142 window_state_( | |
143 ash::wm::GetWindowState(native_app_window->GetNativeWindow())) { | |
144 // Add a window state observer to exit fullscreen properly in case | |
145 // fullscreen is exited without going through AppWindow::Restore(). This | |
146 // is the case when exiting immersive fullscreen via the "Restore" window | |
147 // control. | |
148 // TODO(pkotwicz): This is a hack. Remove ASAP. http://crbug.com/319048 | |
149 window_state_->AddObserver(this); | |
150 window_state_->window()->AddObserver(this); | |
151 } | |
152 virtual ~NativeAppWindowStateDelegate(){ | |
153 if (window_state_) { | |
154 window_state_->RemoveObserver(this); | |
155 window_state_->window()->RemoveObserver(this); | |
156 } | |
157 } | |
158 | |
159 private: | |
160 // Overridden from ash::wm::WindowStateDelegate. | |
161 virtual bool ToggleFullscreen(ash::wm::WindowState* window_state) OVERRIDE { | |
162 // Windows which cannot be maximized should not be fullscreened. | |
163 DCHECK(window_state->IsFullscreen() || window_state->CanMaximize()); | |
164 if (window_state->IsFullscreen()) | |
165 app_window_->Restore(); | |
166 else if (window_state->CanMaximize()) | |
167 app_window_->OSFullscreen(); | |
168 return true; | |
169 } | |
170 | |
171 // Overridden from ash::wm::WindowStateObserver: | |
172 virtual void OnPostWindowShowTypeChange( | |
173 ash::wm::WindowState* window_state, | |
174 ash::wm::WindowShowType old_type) OVERRIDE { | |
175 if (!window_state->IsFullscreen() && !window_state->IsMinimized() && | |
176 app_window_->GetBaseWindow()->IsFullscreenOrPending()) { | |
177 app_window_->Restore(); | |
178 // Usually OnNativeWindowChanged() is called when the window bounds are | |
179 // changed as a result of a show type change. Because the change in show | |
180 // type has already occurred, we need to call OnNativeWindowChanged() | |
181 // explicitly. | |
182 app_window_->OnNativeWindowChanged(); | |
183 } | |
184 } | |
185 | |
186 // Overridden from aura::WindowObserver: | |
187 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE { | |
188 window_state_->RemoveObserver(this); | |
189 window_state_->window()->RemoveObserver(this); | |
190 window_state_ = NULL; | |
191 } | |
192 | |
193 // Not owned. | |
194 AppWindow* app_window_; | |
195 ash::wm::WindowState* window_state_; | |
196 | |
197 DISALLOW_COPY_AND_ASSIGN(NativeAppWindowStateDelegate); | |
198 }; | |
199 #endif // USE_ASH | |
200 | |
201 } // namespace | |
202 | |
203 NativeAppWindowViews::NativeAppWindowViews() | |
204 : web_view_(NULL), | |
205 window_(NULL), | |
206 is_fullscreen_(false), | |
207 weak_ptr_factory_(this) { | |
208 } | |
209 | |
210 void NativeAppWindowViews::Init(apps::AppWindow* app_window, | |
211 const AppWindow::CreateParams& create_params) { | |
212 app_window_ = app_window; | 37 app_window_ = app_window; |
213 frameless_ = create_params.frame == AppWindow::FRAME_NONE; | 38 frameless_ = create_params.frame == AppWindow::FRAME_NONE; |
214 has_frame_color_ = create_params.has_frame_color; | |
215 frame_color_ = create_params.frame_color; | |
216 transparent_background_ = create_params.transparent_background; | 39 transparent_background_ = create_params.transparent_background; |
217 resizable_ = create_params.resizable; | 40 resizable_ = create_params.resizable; |
218 Observe(web_contents()); | 41 Observe(app_window_->web_contents()); |
219 | 42 |
220 window_ = new views::Widget; | 43 window_ = new views::Widget; |
221 if (create_params.window_type == AppWindow::WINDOW_TYPE_PANEL || | 44 InitializeWindow(app_window, create_params); |
222 create_params.window_type == AppWindow::WINDOW_TYPE_V1_PANEL) { | |
223 InitializePanelWindow(create_params); | |
224 } else { | |
225 InitializeDefaultWindow(create_params); | |
226 } | |
227 extension_keybinding_registry_.reset(new ExtensionKeybindingRegistryViews( | |
228 Profile::FromBrowserContext(browser_context()), | |
229 window_->GetFocusManager(), | |
230 extensions::ExtensionKeybindingRegistry::PLATFORM_APPS_ONLY, | |
231 app_window_)); | |
232 | 45 |
233 OnViewWasResized(); | 46 OnViewWasResized(); |
234 window_->AddObserver(this); | 47 window_->AddObserver(this); |
235 | |
236 #if defined(OS_WIN) | |
237 if (ShouldUseNativeFrame() && | |
238 chrome::GetHostDesktopTypeForNativeWindow(window_->GetNativeWindow()) != | |
239 chrome::HOST_DESKTOP_TYPE_ASH) { | |
240 InstallEasyResizeTargeterOnContainer(); | |
241 } | |
242 #endif | |
243 } | 48 } |
244 | 49 |
245 NativeAppWindowViews::~NativeAppWindowViews() { | 50 BaseNativeAppWindowViews::~BaseNativeAppWindowViews() { |
246 web_view_->SetWebContents(NULL); | 51 web_view_->SetWebContents(NULL); |
247 } | 52 } |
248 | 53 |
249 void NativeAppWindowViews::OnBeforeWidgetInit( | 54 void BaseNativeAppWindowViews::InitializeWindow( |
250 views::Widget::InitParams* init_params, | 55 apps::AppWindow* app_window, |
251 views::Widget* widget) {} | 56 const apps::AppWindow::CreateParams& create_params) { |
252 | 57 // Stub implementation. See also NativeAppWindowViews in Chrome. |
253 void NativeAppWindowViews::InitializeDefaultWindow( | |
254 const AppWindow::CreateParams& create_params) { | |
255 std::string app_name = | |
256 web_app::GenerateApplicationNameFromExtensionId(extension()->id()); | |
257 | |
258 views::Widget::InitParams init_params(views::Widget::InitParams::TYPE_WINDOW); | 58 views::Widget::InitParams init_params(views::Widget::InitParams::TYPE_WINDOW); |
259 init_params.delegate = this; | 59 init_params.delegate = this; |
260 init_params.remove_standard_frame = !ShouldUseNativeFrame(); | |
261 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | |
262 // On Linux, remove the standard frame. Instead, we will use CustomFrameView | |
263 // to draw a native-like frame. | |
264 // TODO(mgiuca): Remove this during fix for http://crbug.com/322256. | |
265 init_params.remove_standard_frame = true; | |
266 #endif | |
267 init_params.use_system_default_icon = true; | |
268 // TODO(erg): Conceptually, these are toplevel windows, but we theoretically | |
269 // could plumb context through to here in some cases. | |
270 init_params.top_level = true; | 60 init_params.top_level = true; |
271 if (create_params.transparent_background) | |
272 init_params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | |
273 init_params.keep_on_top = create_params.always_on_top; | 61 init_params.keep_on_top = create_params.always_on_top; |
274 gfx::Rect window_bounds = create_params.bounds; | |
275 bool position_specified = | |
276 window_bounds.x() != INT_MIN && window_bounds.y() != INT_MIN; | |
277 if (position_specified && !window_bounds.IsEmpty()) | |
278 init_params.bounds = window_bounds; | |
279 | |
280 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | |
281 // Set up a custom WM_CLASS for app windows. This allows task switchers in | |
282 // X11 environments to distinguish them from main browser windows. | |
283 init_params.wm_class_name = web_app::GetWMClassFromAppName(app_name); | |
284 init_params.wm_class_class = ShellIntegrationLinux::GetProgramClassName(); | |
285 const char kX11WindowRoleApp[] = "app"; | |
286 init_params.wm_role_name = std::string(kX11WindowRoleApp); | |
287 #endif | |
288 | |
289 OnBeforeWidgetInit(&init_params, window_); | |
290 window_->Init(init_params); | 62 window_->Init(init_params); |
291 | 63 window_->CenterWindow(create_params.bounds.size()); |
292 gfx::Rect adjusted_bounds = window_bounds; | |
293 adjusted_bounds.Inset(-GetFrameInsets()); | |
294 // Center window if no position was specified. | |
295 if (!position_specified) | |
296 window_->CenterWindow(adjusted_bounds.size()); | |
297 else if (!adjusted_bounds.IsEmpty() && adjusted_bounds != window_bounds) | |
298 window_->SetBounds(adjusted_bounds); | |
299 | |
300 // Register accelarators supported by app windows. | |
301 // TODO(jeremya/stevenjb): should these be registered for panels too? | |
302 views::FocusManager* focus_manager = GetFocusManager(); | |
303 const std::map<ui::Accelerator, int>& accelerator_table = | |
304 GetAcceleratorTable(); | |
305 const bool is_kiosk_app_mode = chrome::IsRunningInForcedAppMode(); | |
306 | |
307 // Ensures that kiosk mode accelerators are enabled when in kiosk mode (to be | |
308 // future proof). This is needed because GetAcceleratorTable() uses a static | |
309 // to store data and only checks kiosk mode once. If a platform app is | |
310 // launched before kiosk mode starts, the kiosk accelerators will not be | |
311 // registered. This DCHECK catches the case. | |
312 DCHECK(!is_kiosk_app_mode || | |
313 accelerator_table.size() == | |
314 arraysize(kAppWindowAcceleratorMap) + | |
315 arraysize(kAppWindowKioskAppModeAcceleratorMap)); | |
316 | |
317 for (std::map<ui::Accelerator, int>::const_iterator iter = | |
318 accelerator_table.begin(); | |
319 iter != accelerator_table.end(); ++iter) { | |
320 if (is_kiosk_app_mode && !chrome::IsCommandAllowedInAppMode(iter->second)) | |
321 continue; | |
322 | |
323 focus_manager->RegisterAccelerator( | |
324 iter->first, ui::AcceleratorManager::kNormalPriority, this); | |
325 } | |
326 } | |
327 | |
328 void NativeAppWindowViews::InitializePanelWindow( | |
329 const AppWindow::CreateParams& create_params) { | |
330 views::Widget::InitParams params(views::Widget::InitParams::TYPE_PANEL); | |
331 params.delegate = this; | |
332 | |
333 preferred_size_ = gfx::Size(create_params.bounds.width(), | |
334 create_params.bounds.height()); | |
335 if (preferred_size_.width() == 0) | |
336 preferred_size_.set_width(kDefaultPanelWidth); | |
337 else if (preferred_size_.width() < kMinPanelWidth) | |
338 preferred_size_.set_width(kMinPanelWidth); | |
339 | |
340 if (preferred_size_.height() == 0) | |
341 preferred_size_.set_height(kDefaultPanelHeight); | |
342 else if (preferred_size_.height() < kMinPanelHeight) | |
343 preferred_size_.set_height(kMinPanelHeight); | |
344 #if defined(USE_ASH) | |
345 if (ash::Shell::HasInstance()) { | |
346 // Open a new panel on the target root. | |
347 aura::Window* target = ash::Shell::GetTargetRootWindow(); | |
348 params.bounds = ash::ScreenUtil::ConvertRectToScreen( | |
349 target, gfx::Rect(preferred_size_)); | |
350 } else { | |
351 params.bounds = gfx::Rect(preferred_size_); | |
352 } | |
353 #else | |
354 params.bounds = gfx::Rect(preferred_size_); | |
355 #endif | |
356 // TODO(erg): Conceptually, these are toplevel windows, but we theoretically | |
357 // could plumb context through to here in some cases. | |
358 params.top_level = true; | |
359 window_->Init(params); | |
360 window_->set_focus_on_creation(create_params.focused); | |
361 | |
362 #if defined(USE_ASH) | |
363 if (create_params.state == ui::SHOW_STATE_DETACHED) { | |
364 gfx::Rect window_bounds(create_params.bounds.x(), | |
365 create_params.bounds.y(), | |
366 preferred_size_.width(), | |
367 preferred_size_.height()); | |
368 aura::Window* native_window = GetNativeWindow(); | |
369 ash::wm::GetWindowState(native_window)->set_panel_attached(false); | |
370 aura::client::ParentWindowWithContext(native_window, | |
371 native_window->GetRootWindow(), | |
372 native_window->GetBoundsInScreen()); | |
373 window_->SetBounds(window_bounds); | |
374 } | |
375 #else | |
376 // TODO(stevenjb): NativeAppWindow panels need to be implemented for other | |
377 // platforms. | |
378 #endif | |
379 } | |
380 | |
381 bool NativeAppWindowViews::ShouldUseNativeFrame() const { | |
382 return !frameless_ & !has_frame_color_; | |
383 } | |
384 | |
385 void NativeAppWindowViews::InstallEasyResizeTargeterOnContainer() const { | |
386 aura::Window* root_window = window_->GetNativeWindow()->GetRootWindow(); | |
387 gfx::Insets inset(kResizeInsideBoundsSize, kResizeInsideBoundsSize, | |
388 kResizeInsideBoundsSize, kResizeInsideBoundsSize); | |
389 root_window->SetEventTargeter(scoped_ptr<ui::EventTargeter>( | |
390 new wm::EasyResizeWindowTargeter(root_window, inset, inset))); | |
391 } | |
392 | |
393 apps::AppWindowFrameView* NativeAppWindowViews::CreateAppWindowFrameView() { | |
394 // By default the user can resize the window from slightly inside the bounds. | |
395 int resize_inside_bounds_size = kResizeInsideBoundsSize; | |
396 int resize_outside_bounds_size = 0; | |
397 int resize_outside_scale_for_touch = 1; | |
398 int resize_area_corner_size = kResizeAreaCornerSize; | |
399 #if defined(USE_ASH) | |
400 // For Aura windows on the Ash desktop the sizes are different and the user | |
401 // can resize the window from slightly outside the bounds as well. | |
402 if (chrome::IsNativeWindowInAsh(window_->GetNativeWindow())) { | |
403 resize_inside_bounds_size = ash::kResizeInsideBoundsSize; | |
404 resize_outside_bounds_size = ash::kResizeOutsideBoundsSize; | |
405 resize_outside_scale_for_touch = ash::kResizeOutsideBoundsScaleForTouch; | |
406 resize_area_corner_size = ash::kResizeAreaCornerSize; | |
407 } | |
408 #endif | |
409 apps::AppWindowFrameView* frame_view = new apps::AppWindowFrameView(this); | |
410 frame_view->Init(window_, | |
411 frame_color_, | |
412 resize_inside_bounds_size, | |
413 resize_outside_bounds_size, | |
414 resize_outside_scale_for_touch, | |
415 resize_area_corner_size); | |
416 return frame_view; | |
417 } | 64 } |
418 | 65 |
419 // ui::BaseWindow implementation. | 66 // ui::BaseWindow implementation. |
420 | 67 |
421 bool NativeAppWindowViews::IsActive() const { | 68 bool BaseNativeAppWindowViews::IsActive() const { |
422 return window_->IsActive(); | 69 return window_->IsActive(); |
423 } | 70 } |
424 | 71 |
425 bool NativeAppWindowViews::IsMaximized() const { | 72 bool BaseNativeAppWindowViews::IsMaximized() const { |
426 return window_->IsMaximized(); | 73 return window_->IsMaximized(); |
427 } | 74 } |
428 | 75 |
429 bool NativeAppWindowViews::IsMinimized() const { | 76 bool BaseNativeAppWindowViews::IsMinimized() const { |
430 return window_->IsMinimized(); | 77 return window_->IsMinimized(); |
431 } | 78 } |
432 | 79 |
433 bool NativeAppWindowViews::IsFullscreen() const { | 80 bool BaseNativeAppWindowViews::IsFullscreen() const { |
434 return window_->IsFullscreen(); | 81 return window_->IsFullscreen(); |
435 } | 82 } |
436 | 83 |
437 gfx::NativeWindow NativeAppWindowViews::GetNativeWindow() { | 84 gfx::NativeWindow BaseNativeAppWindowViews::GetNativeWindow() { |
438 return window_->GetNativeWindow(); | 85 return window_->GetNativeWindow(); |
439 } | 86 } |
440 | 87 |
441 gfx::Rect NativeAppWindowViews::GetRestoredBounds() const { | 88 gfx::Rect BaseNativeAppWindowViews::GetRestoredBounds() const { |
442 return window_->GetRestoredBounds(); | 89 return window_->GetRestoredBounds(); |
443 } | 90 } |
444 | 91 |
445 ui::WindowShowState NativeAppWindowViews::GetRestoredState() const { | 92 ui::WindowShowState BaseNativeAppWindowViews::GetRestoredState() const { |
| 93 // Stub implementation. See also NativeAppWindowViews in Chrome. |
446 if (IsMaximized()) | 94 if (IsMaximized()) |
447 return ui::SHOW_STATE_MAXIMIZED; | 95 return ui::SHOW_STATE_MAXIMIZED; |
448 if (IsFullscreen()) { | 96 if (IsFullscreen()) |
449 #if defined(USE_ASH) | |
450 if (immersive_fullscreen_controller_.get() && | |
451 immersive_fullscreen_controller_->IsEnabled()) { | |
452 // Restore windows which were previously in immersive fullscreen to | |
453 // maximized. Restoring the window to a different fullscreen type | |
454 // makes for a bad experience. | |
455 return ui::SHOW_STATE_MAXIMIZED; | |
456 } | |
457 #endif | |
458 return ui::SHOW_STATE_FULLSCREEN; | 97 return ui::SHOW_STATE_FULLSCREEN; |
459 } | |
460 #if defined(USE_ASH) | |
461 // Use kRestoreShowStateKey in case a window is minimized/hidden. | |
462 ui::WindowShowState restore_state = | |
463 window_->GetNativeWindow()->GetProperty( | |
464 aura::client::kRestoreShowStateKey); | |
465 // Whitelist states to return so that invalid and transient states | |
466 // are not saved and used to restore windows when they are recreated. | |
467 switch (restore_state) { | |
468 case ui::SHOW_STATE_NORMAL: | |
469 case ui::SHOW_STATE_MAXIMIZED: | |
470 case ui::SHOW_STATE_FULLSCREEN: | |
471 case ui::SHOW_STATE_DETACHED: | |
472 return restore_state; | |
473 | |
474 case ui::SHOW_STATE_DEFAULT: | |
475 case ui::SHOW_STATE_MINIMIZED: | |
476 case ui::SHOW_STATE_INACTIVE: | |
477 case ui::SHOW_STATE_END: | |
478 return ui::SHOW_STATE_NORMAL; | |
479 } | |
480 #endif | |
481 return ui::SHOW_STATE_NORMAL; | 98 return ui::SHOW_STATE_NORMAL; |
482 } | 99 } |
483 | 100 |
484 gfx::Rect NativeAppWindowViews::GetBounds() const { | 101 gfx::Rect BaseNativeAppWindowViews::GetBounds() const { |
485 return window_->GetWindowBoundsInScreen(); | 102 return window_->GetWindowBoundsInScreen(); |
486 } | 103 } |
487 | 104 |
488 void NativeAppWindowViews::Show() { | 105 void BaseNativeAppWindowViews::Show() { |
489 if (window_->IsVisible()) { | 106 if (window_->IsVisible()) { |
490 window_->Activate(); | 107 window_->Activate(); |
491 return; | 108 return; |
492 } | 109 } |
493 | |
494 window_->Show(); | 110 window_->Show(); |
495 } | 111 } |
496 | 112 |
497 void NativeAppWindowViews::ShowInactive() { | 113 void BaseNativeAppWindowViews::ShowInactive() { |
498 if (window_->IsVisible()) | 114 if (window_->IsVisible()) |
499 return; | 115 return; |
| 116 |
500 window_->ShowInactive(); | 117 window_->ShowInactive(); |
501 } | 118 } |
502 | 119 |
503 void NativeAppWindowViews::Hide() { | 120 void BaseNativeAppWindowViews::Hide() { |
504 window_->Hide(); | 121 window_->Hide(); |
505 } | 122 } |
506 | 123 |
507 void NativeAppWindowViews::Close() { | 124 void BaseNativeAppWindowViews::Close() { |
508 window_->Close(); | 125 window_->Close(); |
509 } | 126 } |
510 | 127 |
511 void NativeAppWindowViews::Activate() { | 128 void BaseNativeAppWindowViews::Activate() { |
512 window_->Activate(); | 129 window_->Activate(); |
513 } | 130 } |
514 | 131 |
515 void NativeAppWindowViews::Deactivate() { | 132 void BaseNativeAppWindowViews::Deactivate() { |
516 window_->Deactivate(); | 133 window_->Deactivate(); |
517 } | 134 } |
518 | 135 |
519 void NativeAppWindowViews::Maximize() { | 136 void BaseNativeAppWindowViews::Maximize() { |
520 window_->Maximize(); | 137 window_->Maximize(); |
521 } | 138 } |
522 | 139 |
523 void NativeAppWindowViews::Minimize() { | 140 void BaseNativeAppWindowViews::Minimize() { |
524 window_->Minimize(); | 141 window_->Minimize(); |
525 } | 142 } |
526 | 143 |
527 void NativeAppWindowViews::Restore() { | 144 void BaseNativeAppWindowViews::Restore() { |
528 window_->Restore(); | 145 window_->Restore(); |
529 } | 146 } |
530 | 147 |
531 void NativeAppWindowViews::SetBounds(const gfx::Rect& bounds) { | 148 void BaseNativeAppWindowViews::SetBounds(const gfx::Rect& bounds) { |
532 window_->SetBounds(bounds); | 149 window_->SetBounds(bounds); |
533 } | 150 } |
534 | 151 |
535 void NativeAppWindowViews::FlashFrame(bool flash) { | 152 void BaseNativeAppWindowViews::FlashFrame(bool flash) { |
536 window_->FlashFrame(flash); | 153 window_->FlashFrame(flash); |
537 } | 154 } |
538 | 155 |
539 bool NativeAppWindowViews::IsAlwaysOnTop() const { | 156 bool BaseNativeAppWindowViews::IsAlwaysOnTop() const { |
540 if (app_window_->window_type_is_panel()) { | 157 // Stub implementation. See also NativeAppWindowViews in Chrome. |
541 #if defined(USE_ASH) | 158 return window_->IsAlwaysOnTop(); |
542 return ash::wm::GetWindowState(window_->GetNativeWindow())-> | |
543 panel_attached(); | |
544 #else | |
545 return true; | |
546 #endif | |
547 } else { | |
548 return window_->IsAlwaysOnTop(); | |
549 } | |
550 } | 159 } |
551 | 160 |
552 void NativeAppWindowViews::SetAlwaysOnTop(bool always_on_top) { | 161 void BaseNativeAppWindowViews::SetAlwaysOnTop(bool always_on_top) { |
553 window_->SetAlwaysOnTop(always_on_top); | 162 window_->SetAlwaysOnTop(always_on_top); |
554 } | 163 } |
555 | 164 |
556 void NativeAppWindowViews::ShowContextMenuForView( | 165 gfx::NativeView BaseNativeAppWindowViews::GetHostView() const { |
557 views::View* source, | |
558 const gfx::Point& p, | |
559 ui::MenuSourceType source_type) { | |
560 #if defined(USE_ASH) & defined(OS_CHROMEOS) | |
561 scoped_ptr<ui::MenuModel> model = | |
562 CreateMultiUserContextMenu(app_window_->GetNativeWindow()); | |
563 if (!model.get()) | |
564 return; | |
565 | |
566 // Only show context menu if point is in caption. | |
567 gfx::Point point_in_view_coords(p); | |
568 views::View::ConvertPointFromScreen(window_->non_client_view(), | |
569 &point_in_view_coords); | |
570 int hit_test = window_->non_client_view()->NonClientHitTest( | |
571 point_in_view_coords); | |
572 if (hit_test == HTCAPTION) { | |
573 menu_runner_.reset(new views::MenuRunner(model.get())); | |
574 if (menu_runner_->RunMenuAt(source->GetWidget(), NULL, | |
575 gfx::Rect(p, gfx::Size(0,0)), views::MenuItemView::TOPLEFT, | |
576 source_type, | |
577 views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::CONTEXT_MENU) == | |
578 views::MenuRunner::MENU_DELETED) | |
579 return; | |
580 } | |
581 #endif | |
582 } | |
583 | |
584 gfx::NativeView NativeAppWindowViews::GetHostView() const { | |
585 return window_->GetNativeView(); | 166 return window_->GetNativeView(); |
586 } | 167 } |
587 | 168 |
588 gfx::Point NativeAppWindowViews::GetDialogPosition(const gfx::Size& size) { | 169 gfx::Point BaseNativeAppWindowViews::GetDialogPosition(const gfx::Size& size) { |
589 gfx::Size app_window_size = window_->GetWindowBoundsInScreen().size(); | 170 gfx::Size app_window_size = window_->GetWindowBoundsInScreen().size(); |
590 return gfx::Point(app_window_size.width() / 2 - size.width() / 2, | 171 return gfx::Point(app_window_size.width() / 2 - size.width() / 2, |
591 app_window_size.height() / 2 - size.height() / 2); | 172 app_window_size.height() / 2 - size.height() / 2); |
592 } | 173 } |
593 | 174 |
594 gfx::Size NativeAppWindowViews::GetMaximumDialogSize() { | 175 gfx::Size BaseNativeAppWindowViews::GetMaximumDialogSize() { |
595 return window_->GetWindowBoundsInScreen().size(); | 176 return window_->GetWindowBoundsInScreen().size(); |
596 } | 177 } |
597 | 178 |
598 void NativeAppWindowViews::AddObserver( | 179 void BaseNativeAppWindowViews::AddObserver( |
599 web_modal::ModalDialogHostObserver* observer) { | 180 web_modal::ModalDialogHostObserver* observer) { |
600 observer_list_.AddObserver(observer); | 181 observer_list_.AddObserver(observer); |
601 } | 182 } |
602 void NativeAppWindowViews::RemoveObserver( | 183 void BaseNativeAppWindowViews::RemoveObserver( |
603 web_modal::ModalDialogHostObserver* observer) { | 184 web_modal::ModalDialogHostObserver* observer) { |
604 observer_list_.RemoveObserver(observer); | 185 observer_list_.RemoveObserver(observer); |
605 } | 186 } |
606 | 187 |
607 // Private method. TODO(stevenjb): Move this below InitializePanelWindow() | 188 void BaseNativeAppWindowViews::OnViewWasResized() { |
608 // to match declaration order. | |
609 void NativeAppWindowViews::OnViewWasResized() { | |
610 FOR_EACH_OBSERVER(web_modal::ModalDialogHostObserver, | 189 FOR_EACH_OBSERVER(web_modal::ModalDialogHostObserver, |
611 observer_list_, | 190 observer_list_, |
612 OnPositionRequiresUpdate()); | 191 OnPositionRequiresUpdate()); |
613 } | 192 } |
614 | 193 |
615 // WidgetDelegate implementation. | 194 // WidgetDelegate implementation. |
616 | 195 |
617 void NativeAppWindowViews::OnWidgetMove() { | 196 void BaseNativeAppWindowViews::OnWidgetMove() { |
618 app_window_->OnNativeWindowChanged(); | 197 app_window_->OnNativeWindowChanged(); |
619 } | 198 } |
620 | 199 |
621 views::View* NativeAppWindowViews::GetInitiallyFocusedView() { | 200 views::View* BaseNativeAppWindowViews::GetInitiallyFocusedView() { |
622 return web_view_; | 201 return web_view_; |
623 } | 202 } |
624 | 203 |
625 bool NativeAppWindowViews::CanResize() const { | 204 bool BaseNativeAppWindowViews::CanResize() const { |
626 return resizable_ && !app_window_->size_constraints().HasFixedSize(); | 205 return resizable_ && !app_window_->size_constraints().HasFixedSize(); |
627 } | 206 } |
628 | 207 |
629 bool NativeAppWindowViews::CanMaximize() const { | 208 bool BaseNativeAppWindowViews::CanMaximize() const { |
630 return resizable_ && !app_window_->size_constraints().HasMaximumSize() && | 209 return resizable_ && !app_window_->size_constraints().HasMaximumSize() && |
631 !app_window_->window_type_is_panel(); | 210 !app_window_->window_type_is_panel(); |
632 } | 211 } |
633 | 212 |
634 base::string16 NativeAppWindowViews::GetWindowTitle() const { | 213 base::string16 BaseNativeAppWindowViews::GetWindowTitle() const { |
635 return base::string16(); | 214 return app_window_->GetTitle(); |
636 } | 215 } |
637 | 216 |
638 bool NativeAppWindowViews::ShouldShowWindowTitle() const { | 217 bool BaseNativeAppWindowViews::ShouldShowWindowTitle() const { |
639 return app_window_->window_type() == AppWindow::WINDOW_TYPE_V1_PANEL; | 218 return app_window_->window_type() == AppWindow::WINDOW_TYPE_V1_PANEL; |
640 } | 219 } |
641 | 220 |
642 gfx::ImageSkia NativeAppWindowViews::GetWindowAppIcon() { | 221 bool BaseNativeAppWindowViews::ShouldShowWindowIcon() const { |
643 gfx::Image app_icon = app_window_->app_icon(); | |
644 if (app_icon.IsEmpty()) | |
645 return GetWindowIcon(); | |
646 else | |
647 return *app_icon.ToImageSkia(); | |
648 } | |
649 | |
650 gfx::ImageSkia NativeAppWindowViews::GetWindowIcon() { | |
651 content::WebContents* web_contents = app_window_->web_contents(); | |
652 if (web_contents) { | |
653 FaviconTabHelper* favicon_tab_helper = | |
654 FaviconTabHelper::FromWebContents(web_contents); | |
655 gfx::Image app_icon = favicon_tab_helper->GetFavicon(); | |
656 if (!app_icon.IsEmpty()) | |
657 return *app_icon.ToImageSkia(); | |
658 } | |
659 return gfx::ImageSkia(); | |
660 } | |
661 | |
662 bool NativeAppWindowViews::ShouldShowWindowIcon() const { | |
663 return app_window_->window_type() == AppWindow::WINDOW_TYPE_V1_PANEL; | 222 return app_window_->window_type() == AppWindow::WINDOW_TYPE_V1_PANEL; |
664 } | 223 } |
665 | 224 |
666 void NativeAppWindowViews::SaveWindowPlacement(const gfx::Rect& bounds, | 225 void BaseNativeAppWindowViews::SaveWindowPlacement( |
667 ui::WindowShowState show_state) { | 226 const gfx::Rect& bounds, |
| 227 ui::WindowShowState show_state) { |
668 views::WidgetDelegate::SaveWindowPlacement(bounds, show_state); | 228 views::WidgetDelegate::SaveWindowPlacement(bounds, show_state); |
669 app_window_->OnNativeWindowChanged(); | 229 app_window_->OnNativeWindowChanged(); |
670 } | 230 } |
671 | 231 |
672 void NativeAppWindowViews::DeleteDelegate() { | 232 void BaseNativeAppWindowViews::DeleteDelegate() { |
673 window_->RemoveObserver(this); | 233 window_->RemoveObserver(this); |
674 app_window_->OnNativeClose(); | 234 app_window_->OnNativeClose(); |
675 } | 235 } |
676 | 236 |
677 views::Widget* NativeAppWindowViews::GetWidget() { | 237 views::Widget* BaseNativeAppWindowViews::GetWidget() { |
678 return window_; | 238 return window_; |
679 } | 239 } |
680 | 240 |
681 const views::Widget* NativeAppWindowViews::GetWidget() const { | 241 const views::Widget* BaseNativeAppWindowViews::GetWidget() const { |
682 return window_; | 242 return window_; |
683 } | 243 } |
684 | 244 |
685 views::View* NativeAppWindowViews::GetContentsView() { | 245 views::View* BaseNativeAppWindowViews::GetContentsView() { |
686 return this; | 246 return this; |
687 } | 247 } |
688 | 248 |
689 views::NonClientFrameView* NativeAppWindowViews::CreateNonClientFrameView( | 249 bool BaseNativeAppWindowViews::ShouldDescendIntoChildForEventHandling( |
690 views::Widget* widget) { | |
691 #if defined(USE_ASH) | |
692 if (chrome::IsNativeViewInAsh(widget->GetNativeView())) { | |
693 // Set the delegate now because CustomFrameViewAsh sets the | |
694 // WindowStateDelegate if one is not already set. | |
695 ash::wm::GetWindowState(GetNativeWindow())->SetDelegate( | |
696 scoped_ptr<ash::wm::WindowStateDelegate>( | |
697 new NativeAppWindowStateDelegate(app_window_, this)).Pass()); | |
698 | |
699 if (app_window_->window_type_is_panel()) { | |
700 ash::PanelFrameView::FrameType frame_type = frameless_ ? | |
701 ash::PanelFrameView::FRAME_NONE : ash::PanelFrameView::FRAME_ASH; | |
702 views::NonClientFrameView* frame_view = | |
703 new ash::PanelFrameView(widget, frame_type); | |
704 frame_view->set_context_menu_controller(this); | |
705 return frame_view; | |
706 } | |
707 | |
708 if (!frameless_) { | |
709 ash::CustomFrameViewAsh* custom_frame_view = | |
710 new ash::CustomFrameViewAsh(widget); | |
711 #if defined(OS_CHROMEOS) | |
712 // Non-frameless app windows can be put into immersive fullscreen. | |
713 // TODO(pkotwicz): Investigate if immersive fullscreen can be enabled for | |
714 // Windows Ash. | |
715 if (ash::switches::UseImmersiveFullscreenForAllWindows()) { | |
716 immersive_fullscreen_controller_.reset( | |
717 new ash::ImmersiveFullscreenController()); | |
718 custom_frame_view->InitImmersiveFullscreenControllerForView( | |
719 immersive_fullscreen_controller_.get()); | |
720 } | |
721 #endif | |
722 custom_frame_view->GetHeaderView()->set_context_menu_controller(this); | |
723 return custom_frame_view; | |
724 } | |
725 } | |
726 #endif | |
727 if (!ShouldUseNativeFrame()) | |
728 return CreateAppWindowFrameView(); | |
729 return views::WidgetDelegateView::CreateNonClientFrameView(widget); | |
730 } | |
731 | |
732 bool NativeAppWindowViews::WidgetHasHitTestMask() const { | |
733 return shape_ != NULL; | |
734 } | |
735 | |
736 void NativeAppWindowViews::GetWidgetHitTestMask(gfx::Path* mask) const { | |
737 shape_->getBoundaryPath(mask); | |
738 } | |
739 | |
740 bool NativeAppWindowViews::ShouldDescendIntoChildForEventHandling( | |
741 gfx::NativeView child, | 250 gfx::NativeView child, |
742 const gfx::Point& location) { | 251 const gfx::Point& location) { |
743 #if defined(USE_AURA) | 252 #if defined(USE_AURA) |
744 if (child->Contains(web_view_->web_contents()->GetView()->GetNativeView())) { | 253 if (child->Contains(web_view_->web_contents()->GetView()->GetNativeView())) { |
745 // App window should claim mouse events that fall within the draggable | 254 // App window should claim mouse events that fall within the draggable |
746 // region. | 255 // region. |
747 return !draggable_region_.get() || | 256 return !draggable_region_.get() || |
748 !draggable_region_->contains(location.x(), location.y()); | 257 !draggable_region_->contains(location.x(), location.y()); |
749 } | 258 } |
750 #endif | 259 #endif |
751 | 260 |
752 return true; | 261 return true; |
753 } | 262 } |
754 | 263 |
755 // WidgetObserver implementation. | 264 // WidgetObserver implementation. |
756 | 265 |
757 void NativeAppWindowViews::OnWidgetVisibilityChanged(views::Widget* widget, | 266 void BaseNativeAppWindowViews::OnWidgetVisibilityChanged(views::Widget* widget, |
758 bool visible) { | 267 bool visible) { |
759 app_window_->OnNativeWindowChanged(); | 268 app_window_->OnNativeWindowChanged(); |
760 } | 269 } |
761 | 270 |
762 void NativeAppWindowViews::OnWidgetActivationChanged(views::Widget* widget, | 271 void BaseNativeAppWindowViews::OnWidgetActivationChanged(views::Widget* widget, |
763 bool active) { | 272 bool active) { |
764 app_window_->OnNativeWindowChanged(); | 273 app_window_->OnNativeWindowChanged(); |
765 if (active) | 274 if (active) |
766 app_window_->OnNativeWindowActivated(); | 275 app_window_->OnNativeWindowActivated(); |
767 } | 276 } |
768 | 277 |
769 // WebContentsObserver implementation. | 278 // WebContentsObserver implementation. |
770 | 279 |
771 void NativeAppWindowViews::RenderViewCreated( | 280 void BaseNativeAppWindowViews::RenderViewCreated( |
772 content::RenderViewHost* render_view_host) { | 281 content::RenderViewHost* render_view_host) { |
773 if (transparent_background_) { | 282 if (transparent_background_) { |
774 // Use a background with transparency to trigger transparency in Webkit. | 283 // Use a background with transparency to trigger transparency in Webkit. |
775 SkBitmap background; | 284 SkBitmap background; |
776 background.setConfig(SkBitmap::kARGB_8888_Config, 1, 1); | 285 background.setConfig(SkBitmap::kARGB_8888_Config, 1, 1); |
777 background.allocPixels(); | 286 background.allocPixels(); |
778 background.eraseARGB(0x00, 0x00, 0x00, 0x00); | 287 background.eraseARGB(0x00, 0x00, 0x00, 0x00); |
779 | 288 |
780 content::RenderWidgetHostView* view = render_view_host->GetView(); | 289 content::RenderWidgetHostView* view = render_view_host->GetView(); |
781 DCHECK(view); | 290 DCHECK(view); |
782 view->SetBackground(background); | 291 view->SetBackground(background); |
783 } | 292 } |
784 } | 293 } |
785 | 294 |
786 void NativeAppWindowViews::RenderViewHostChanged( | 295 void BaseNativeAppWindowViews::RenderViewHostChanged( |
787 content::RenderViewHost* old_host, | 296 content::RenderViewHost* old_host, |
788 content::RenderViewHost* new_host) { | 297 content::RenderViewHost* new_host) { |
789 OnViewWasResized(); | 298 OnViewWasResized(); |
790 } | 299 } |
791 | 300 |
792 // views::View implementation. | 301 // views::View implementation. |
793 | 302 |
794 void NativeAppWindowViews::Layout() { | 303 void BaseNativeAppWindowViews::Layout() { |
795 DCHECK(web_view_); | 304 DCHECK(web_view_); |
796 web_view_->SetBounds(0, 0, width(), height()); | 305 web_view_->SetBounds(0, 0, width(), height()); |
797 OnViewWasResized(); | 306 OnViewWasResized(); |
798 } | 307 } |
799 | 308 |
800 void NativeAppWindowViews::ViewHierarchyChanged( | 309 void BaseNativeAppWindowViews::ViewHierarchyChanged( |
801 const ViewHierarchyChangedDetails& details) { | 310 const ViewHierarchyChangedDetails& details) { |
802 if (details.is_add && details.child == this) { | 311 if (details.is_add && details.child == this) { |
803 web_view_ = new views::WebView(NULL); | 312 web_view_ = new views::WebView(NULL); |
804 AddChildView(web_view_); | 313 AddChildView(web_view_); |
805 web_view_->SetWebContents(web_contents()); | 314 web_view_->SetWebContents(app_window_->web_contents()); |
806 } | 315 } |
807 } | 316 } |
808 | 317 |
809 gfx::Size NativeAppWindowViews::GetPreferredSize() { | 318 gfx::Size BaseNativeAppWindowViews::GetMinimumSize() { |
810 if (!preferred_size_.IsEmpty()) | |
811 return preferred_size_; | |
812 return views::View::GetPreferredSize(); | |
813 } | |
814 | |
815 gfx::Size NativeAppWindowViews::GetMinimumSize() { | |
816 return app_window_->size_constraints().GetMinimumSize(); | 319 return app_window_->size_constraints().GetMinimumSize(); |
817 } | 320 } |
818 | 321 |
819 gfx::Size NativeAppWindowViews::GetMaximumSize() { | 322 gfx::Size BaseNativeAppWindowViews::GetMaximumSize() { |
820 return app_window_->size_constraints().GetMaximumSize(); | 323 return app_window_->size_constraints().GetMaximumSize(); |
821 } | 324 } |
822 | 325 |
823 void NativeAppWindowViews::OnFocus() { | 326 void BaseNativeAppWindowViews::OnFocus() { |
824 web_view_->RequestFocus(); | 327 web_view_->RequestFocus(); |
825 } | 328 } |
826 | 329 |
827 bool NativeAppWindowViews::AcceleratorPressed( | |
828 const ui::Accelerator& accelerator) { | |
829 const std::map<ui::Accelerator, int>& accelerator_table = | |
830 GetAcceleratorTable(); | |
831 std::map<ui::Accelerator, int>::const_iterator iter = | |
832 accelerator_table.find(accelerator); | |
833 DCHECK(iter != accelerator_table.end()); | |
834 int command_id = iter->second; | |
835 switch (command_id) { | |
836 case IDC_CLOSE_WINDOW: | |
837 Close(); | |
838 return true; | |
839 case IDC_ZOOM_MINUS: | |
840 chrome_page_zoom::Zoom(web_view_->GetWebContents(), | |
841 content::PAGE_ZOOM_OUT); | |
842 return true; | |
843 case IDC_ZOOM_NORMAL: | |
844 chrome_page_zoom::Zoom(web_view_->GetWebContents(), | |
845 content::PAGE_ZOOM_RESET); | |
846 return true; | |
847 case IDC_ZOOM_PLUS: | |
848 chrome_page_zoom::Zoom(web_view_->GetWebContents(), | |
849 content::PAGE_ZOOM_IN); | |
850 return true; | |
851 default: | |
852 NOTREACHED() << "Unknown accelerator sent to app window."; | |
853 } | |
854 return false; | |
855 } | |
856 | |
857 // NativeAppWindow implementation. | 330 // NativeAppWindow implementation. |
858 | 331 |
859 void NativeAppWindowViews::SetFullscreen(int fullscreen_types) { | 332 void BaseNativeAppWindowViews::SetFullscreen(int fullscreen_types) { |
860 // Fullscreen not supported by panels. | 333 // Stub implementation. See also NativeAppWindowViews in Chrome. |
861 if (app_window_->window_type_is_panel()) | 334 window_->SetFullscreen(fullscreen_types != AppWindow::FULLSCREEN_TYPE_NONE); |
862 return; | |
863 is_fullscreen_ = (fullscreen_types != AppWindow::FULLSCREEN_TYPE_NONE); | |
864 window_->SetFullscreen(is_fullscreen_); | |
865 | |
866 #if defined(USE_ASH) | |
867 if (immersive_fullscreen_controller_.get()) { | |
868 // |immersive_fullscreen_controller_| should only be set if immersive | |
869 // fullscreen is the fullscreen type used by the OS. | |
870 immersive_fullscreen_controller_->SetEnabled( | |
871 ash::ImmersiveFullscreenController::WINDOW_TYPE_PACKAGED_APP, | |
872 (fullscreen_types & AppWindow::FULLSCREEN_TYPE_OS) != 0); | |
873 // Autohide the shelf instead of hiding the shelf completely when only in | |
874 // OS fullscreen. | |
875 ash::wm::WindowState* window_state = | |
876 ash::wm::GetWindowState(window_->GetNativeWindow()); | |
877 window_state->set_hide_shelf_when_fullscreen(fullscreen_types != | |
878 AppWindow::FULLSCREEN_TYPE_OS); | |
879 DCHECK(ash::Shell::HasInstance()); | |
880 ash::Shell::GetInstance()->UpdateShelfVisibility(); | |
881 } | |
882 #endif | |
883 | |
884 // TODO(jeremya) we need to call RenderViewHost::ExitFullscreen() if we | |
885 // ever drop the window out of fullscreen in response to something that | |
886 // wasn't the app calling webkitCancelFullScreen(). | |
887 } | 335 } |
888 | 336 |
889 bool NativeAppWindowViews::IsFullscreenOrPending() const { | 337 bool BaseNativeAppWindowViews::IsFullscreenOrPending() const { |
890 return is_fullscreen_; | 338 // Stub implementation. See also NativeAppWindowViews in Chrome. |
| 339 return window_->IsFullscreen(); |
891 } | 340 } |
892 | 341 |
893 bool NativeAppWindowViews::IsDetached() const { | 342 bool BaseNativeAppWindowViews::IsDetached() const { |
894 if (!app_window_->window_type_is_panel()) | 343 // Stub implementation. See also NativeAppWindowViews in Chrome. |
895 return false; | |
896 #if defined(USE_ASH) | |
897 return !ash::wm::GetWindowState(window_->GetNativeWindow())->panel_attached(); | |
898 #else | |
899 return false; | 344 return false; |
900 #endif | |
901 } | 345 } |
902 | 346 |
903 void NativeAppWindowViews::UpdateWindowIcon() { | 347 void BaseNativeAppWindowViews::UpdateWindowIcon() { |
904 window_->UpdateWindowIcon(); | 348 window_->UpdateWindowIcon(); |
905 } | 349 } |
906 | 350 |
907 void NativeAppWindowViews::UpdateWindowTitle() { | 351 void BaseNativeAppWindowViews::UpdateWindowTitle() { |
908 window_->UpdateWindowTitle(); | 352 window_->UpdateWindowTitle(); |
909 } | 353 } |
910 | 354 |
911 void NativeAppWindowViews::UpdateBadgeIcon() { | 355 void BaseNativeAppWindowViews::UpdateBadgeIcon() { |
912 const gfx::Image* icon = NULL; | 356 // Stub implementation. See also NativeAppWindowViews in Chrome. |
913 if (!app_window_->badge_icon().IsEmpty()) { | |
914 icon = &app_window_->badge_icon(); | |
915 // chrome::DrawTaskbarDecoration can do interesting things with non-square | |
916 // bitmaps. | |
917 // TODO(benwells): Refactor chrome::DrawTaskbarDecoration to not be avatar | |
918 // specific, and lift this restriction. | |
919 if (icon->Width() != icon->Height()) { | |
920 LOG(ERROR) << "Attempt to set a non-square badge; request ignored."; | |
921 return; | |
922 } | |
923 } | |
924 chrome::DrawTaskbarDecoration(GetNativeWindow(), icon); | |
925 } | 357 } |
926 | 358 |
927 void NativeAppWindowViews::UpdateDraggableRegions( | 359 void BaseNativeAppWindowViews::UpdateDraggableRegions( |
928 const std::vector<extensions::DraggableRegion>& regions) { | 360 const std::vector<extensions::DraggableRegion>& regions) { |
929 // Draggable region is not supported for non-frameless window. | 361 // Draggable region is not supported for non-frameless window. |
930 if (!frameless_) | 362 if (!frameless_) |
931 return; | 363 return; |
932 | 364 |
933 draggable_region_.reset(AppWindow::RawDraggableRegionsToSkRegion(regions)); | 365 draggable_region_.reset(AppWindow::RawDraggableRegionsToSkRegion(regions)); |
934 OnViewWasResized(); | 366 OnViewWasResized(); |
935 } | 367 } |
936 | 368 |
937 SkRegion* NativeAppWindowViews::GetDraggableRegion() { | 369 SkRegion* BaseNativeAppWindowViews::GetDraggableRegion() { |
938 return draggable_region_.get(); | 370 return draggable_region_.get(); |
939 } | 371 } |
940 | 372 |
941 void NativeAppWindowViews::UpdateShape(scoped_ptr<SkRegion> region) { | 373 void BaseNativeAppWindowViews::UpdateShape(scoped_ptr<SkRegion> region) { |
942 bool had_shape = shape_; | 374 // Stub implementation. See also NativeAppWindowViews in Chrome. |
943 shape_ = region.Pass(); | |
944 | |
945 aura::Window* native_window = window_->GetNativeWindow(); | |
946 if (shape_) { | |
947 window_->SetShape(new SkRegion(*shape_)); | |
948 if (!had_shape) { | |
949 native_window->SetEventTargeter(scoped_ptr<ui::EventTargeter>( | |
950 new ShapedAppWindowTargeter(native_window, this))); | |
951 } | |
952 } else { | |
953 window_->SetShape(NULL); | |
954 if (had_shape) | |
955 native_window->SetEventTargeter(scoped_ptr<ui::EventTargeter>()); | |
956 } | |
957 } | 375 } |
958 | 376 |
959 void NativeAppWindowViews::HandleKeyboardEvent( | 377 void BaseNativeAppWindowViews::HandleKeyboardEvent( |
960 const content::NativeWebKeyboardEvent& event) { | 378 const content::NativeWebKeyboardEvent& event) { |
961 unhandled_keyboard_event_handler_.HandleKeyboardEvent(event, | 379 unhandled_keyboard_event_handler_.HandleKeyboardEvent(event, |
962 GetFocusManager()); | 380 GetFocusManager()); |
963 } | 381 } |
964 | 382 |
965 bool NativeAppWindowViews::IsFrameless() const { | 383 bool BaseNativeAppWindowViews::IsFrameless() const { |
966 return frameless_; | 384 return frameless_; |
967 } | 385 } |
968 | 386 |
969 bool NativeAppWindowViews::HasFrameColor() const { return has_frame_color_; } | 387 bool BaseNativeAppWindowViews::HasFrameColor() const { return false; } |
970 | 388 |
971 SkColor NativeAppWindowViews::FrameColor() const { return frame_color_; } | 389 SkColor BaseNativeAppWindowViews::FrameColor() const { return SK_ColorBLACK; } |
972 | 390 |
973 gfx::Insets NativeAppWindowViews::GetFrameInsets() const { | 391 gfx::Insets BaseNativeAppWindowViews::GetFrameInsets() const { |
974 if (frameless_) | 392 if (frameless_) |
975 return gfx::Insets(); | 393 return gfx::Insets(); |
976 | 394 |
977 // The pretend client_bounds passed in need to be large enough to ensure that | 395 // The pretend client_bounds passed in need to be large enough to ensure that |
978 // GetWindowBoundsForClientBounds() doesn't decide that it needs more than | 396 // GetWindowBoundsForClientBounds() doesn't decide that it needs more than |
979 // the specified amount of space to fit the window controls in, and return a | 397 // the specified amount of space to fit the window controls in, and return a |
980 // number larger than the real frame insets. Most window controls are smaller | 398 // number larger than the real frame insets. Most window controls are smaller |
981 // than 1000x1000px, so this should be big enough. | 399 // than 1000x1000px, so this should be big enough. |
982 gfx::Rect client_bounds = gfx::Rect(1000, 1000); | 400 gfx::Rect client_bounds = gfx::Rect(1000, 1000); |
983 gfx::Rect window_bounds = | 401 gfx::Rect window_bounds = |
984 window_->non_client_view()->GetWindowBoundsForClientBounds( | 402 window_->non_client_view()->GetWindowBoundsForClientBounds( |
985 client_bounds); | 403 client_bounds); |
986 return window_bounds.InsetsFrom(client_bounds); | 404 return window_bounds.InsetsFrom(client_bounds); |
987 } | 405 } |
988 | 406 |
989 void NativeAppWindowViews::HideWithApp() {} | 407 void BaseNativeAppWindowViews::HideWithApp() {} |
990 void NativeAppWindowViews::ShowWithApp() {} | 408 |
991 void NativeAppWindowViews::UpdateWindowMinMaxSize() {} | 409 void BaseNativeAppWindowViews::ShowWithApp() {} |
| 410 |
| 411 void BaseNativeAppWindowViews::UpdateWindowMinMaxSize() {} |
OLD | NEW |