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

Side by Side Diff: chrome/browser/ui/views/apps/native_app_window_views.cc

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

Powered by Google App Engine
This is Rietveld 408576698