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

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

Powered by Google App Engine
This is Rietveld 408576698