Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/views/apps/native_app_window_views.h" | 5 #include "chrome/browser/ui/views/apps/native_app_window_views.h" |
| 6 | 6 |
| 7 #include "apps/app_window.h" | 7 #include "apps/app_window.h" |
| 8 #include "apps/ui/views/app_window_frame_view.h" | 8 #include "apps/ui/views/app_window_frame_view.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 246 : web_view_(NULL), | 246 : web_view_(NULL), |
| 247 window_(NULL), | 247 window_(NULL), |
| 248 is_fullscreen_(false), | 248 is_fullscreen_(false), |
| 249 weak_ptr_factory_(this) { | 249 weak_ptr_factory_(this) { |
| 250 } | 250 } |
| 251 | 251 |
| 252 void NativeAppWindowViews::Init(apps::AppWindow* app_window, | 252 void NativeAppWindowViews::Init(apps::AppWindow* app_window, |
| 253 const AppWindow::CreateParams& create_params) { | 253 const AppWindow::CreateParams& create_params) { |
| 254 app_window_ = app_window; | 254 app_window_ = app_window; |
| 255 frameless_ = create_params.frame == AppWindow::FRAME_NONE; | 255 frameless_ = create_params.frame == AppWindow::FRAME_NONE; |
| 256 has_frame_color_ = create_params.has_frame_color; | |
| 257 frame_color_ = create_params.frame_color; | |
| 256 transparent_background_ = create_params.transparent_background; | 258 transparent_background_ = create_params.transparent_background; |
| 257 resizable_ = create_params.resizable; | 259 resizable_ = create_params.resizable; |
| 258 Observe(web_contents()); | 260 Observe(web_contents()); |
| 259 | 261 |
| 260 window_ = new views::Widget; | 262 window_ = new views::Widget; |
| 261 if (create_params.window_type == AppWindow::WINDOW_TYPE_PANEL || | 263 if (create_params.window_type == AppWindow::WINDOW_TYPE_PANEL || |
| 262 create_params.window_type == AppWindow::WINDOW_TYPE_V1_PANEL) { | 264 create_params.window_type == AppWindow::WINDOW_TYPE_V1_PANEL) { |
| 263 InitializePanelWindow(create_params); | 265 InitializePanelWindow(create_params); |
| 264 } else { | 266 } else { |
| 265 InitializeDefaultWindow(create_params); | 267 InitializeDefaultWindow(create_params); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 282 views::Widget::InitParams* init_params, | 284 views::Widget::InitParams* init_params, |
| 283 views::Widget* widget) {} | 285 views::Widget* widget) {} |
| 284 | 286 |
| 285 void NativeAppWindowViews::InitializeDefaultWindow( | 287 void NativeAppWindowViews::InitializeDefaultWindow( |
| 286 const AppWindow::CreateParams& create_params) { | 288 const AppWindow::CreateParams& create_params) { |
| 287 std::string app_name = | 289 std::string app_name = |
| 288 web_app::GenerateApplicationNameFromExtensionId(extension()->id()); | 290 web_app::GenerateApplicationNameFromExtensionId(extension()->id()); |
| 289 | 291 |
| 290 views::Widget::InitParams init_params(views::Widget::InitParams::TYPE_WINDOW); | 292 views::Widget::InitParams init_params(views::Widget::InitParams::TYPE_WINDOW); |
| 291 init_params.delegate = this; | 293 init_params.delegate = this; |
| 292 init_params.remove_standard_frame = ShouldUseChromeStyleFrame(); | 294 init_params.remove_standard_frame = !ShouldUseNativeFrame(); |
| 293 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 295 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 294 // On Linux, remove the standard frame. Instead, we will use CustomFrameView | 296 // On Linux, remove the standard frame. Instead, we will use CustomFrameView |
| 295 // to draw a native-like frame. | 297 // to draw a native-like frame. |
| 296 // TODO(mgiuca): Remove this during fix for http://crbug.com/322256. | 298 // TODO(mgiuca): Remove this during fix for http://crbug.com/322256. |
| 297 init_params.remove_standard_frame = true; | 299 init_params.remove_standard_frame = true; |
| 298 #endif | 300 #endif |
| 299 init_params.use_system_default_icon = true; | 301 init_params.use_system_default_icon = true; |
| 300 // TODO(erg): Conceptually, these are toplevel windows, but we theoretically | 302 // TODO(erg): Conceptually, these are toplevel windows, but we theoretically |
| 301 // could plumb context through to here in some cases. | 303 // could plumb context through to here in some cases. |
| 302 init_params.top_level = true; | 304 init_params.top_level = true; |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 446 native_window->GetRootWindow(), | 448 native_window->GetRootWindow(), |
| 447 native_window->GetBoundsInScreen()); | 449 native_window->GetBoundsInScreen()); |
| 448 window_->SetBounds(window_bounds); | 450 window_->SetBounds(window_bounds); |
| 449 } | 451 } |
| 450 #else | 452 #else |
| 451 // TODO(stevenjb): NativeAppWindow panels need to be implemented for other | 453 // TODO(stevenjb): NativeAppWindow panels need to be implemented for other |
| 452 // platforms. | 454 // platforms. |
| 453 #endif | 455 #endif |
| 454 } | 456 } |
| 455 | 457 |
| 456 bool NativeAppWindowViews::ShouldUseChromeStyleFrame() const { | 458 bool NativeAppWindowViews::ShouldUseNativeFrame() const { |
|
Matt Giuca
2014/02/18 06:03:18
I'm concerned that this will break the --apps-use-
benwells
2014/02/18 07:47:25
Good one, done.
Matt Giuca
2014/02/19 02:26:43
So, to confirm: you're happy for stable channel us
| |
| 457 if (frameless_) | 459 return !frameless_ & !has_frame_color_; |
| 458 return true; | |
| 459 | |
| 460 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | |
| 461 // Linux always uses native style frames. | |
| 462 return false; | |
| 463 #endif | |
| 464 | |
| 465 return !CommandLine::ForCurrentProcess()->HasSwitch( | |
| 466 switches::kAppsUseNativeFrame); | |
| 467 } | 460 } |
| 468 | 461 |
| 469 apps::AppWindowFrameView* NativeAppWindowViews::CreateAppWindowFrameView() { | 462 apps::AppWindowFrameView* NativeAppWindowViews::CreateAppWindowFrameView() { |
| 470 // By default the user can resize the window from slightly inside the bounds. | 463 // By default the user can resize the window from slightly inside the bounds. |
| 471 int resize_inside_bounds_size = kResizeInsideBoundsSize; | 464 int resize_inside_bounds_size = kResizeInsideBoundsSize; |
| 472 int resize_outside_bounds_size = 0; | 465 int resize_outside_bounds_size = 0; |
| 473 int resize_outside_scale_for_touch = 1; | 466 int resize_outside_scale_for_touch = 1; |
| 474 int resize_area_corner_size = kResizeAreaCornerSize; | 467 int resize_area_corner_size = kResizeAreaCornerSize; |
| 475 #if defined(USE_ASH) | 468 #if defined(USE_ASH) |
| 476 // For Aura windows on the Ash desktop the sizes are different and the user | 469 // For Aura windows on the Ash desktop the sizes are different and the user |
| 477 // can resize the window from slightly outside the bounds as well. | 470 // can resize the window from slightly outside the bounds as well. |
| 478 if (chrome::IsNativeWindowInAsh(window_->GetNativeWindow())) { | 471 if (chrome::IsNativeWindowInAsh(window_->GetNativeWindow())) { |
| 479 resize_inside_bounds_size = ash::kResizeInsideBoundsSize; | 472 resize_inside_bounds_size = ash::kResizeInsideBoundsSize; |
| 480 resize_outside_bounds_size = ash::kResizeOutsideBoundsSize; | 473 resize_outside_bounds_size = ash::kResizeOutsideBoundsSize; |
| 481 resize_outside_scale_for_touch = ash::kResizeOutsideBoundsScaleForTouch; | 474 resize_outside_scale_for_touch = ash::kResizeOutsideBoundsScaleForTouch; |
| 482 resize_area_corner_size = ash::kResizeAreaCornerSize; | 475 resize_area_corner_size = ash::kResizeAreaCornerSize; |
| 483 } | 476 } |
| 484 #endif | 477 #endif |
| 485 apps::AppWindowFrameView* frame_view = new apps::AppWindowFrameView(this); | 478 apps::AppWindowFrameView* frame_view = new apps::AppWindowFrameView(this); |
| 486 frame_view->Init(window_, | 479 frame_view->Init(window_, |
| 480 frame_color_, | |
| 487 resize_inside_bounds_size, | 481 resize_inside_bounds_size, |
| 488 resize_outside_bounds_size, | 482 resize_outside_bounds_size, |
| 489 resize_outside_scale_for_touch, | 483 resize_outside_scale_for_touch, |
| 490 resize_area_corner_size); | 484 resize_area_corner_size); |
| 491 return frame_view; | 485 return frame_view; |
| 492 } | 486 } |
| 493 | 487 |
| 494 // ui::BaseWindow implementation. | 488 // ui::BaseWindow implementation. |
| 495 | 489 |
| 496 bool NativeAppWindowViews::IsActive() const { | 490 bool NativeAppWindowViews::IsActive() const { |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 700 bool NativeAppWindowViews::CanResize() const { | 694 bool NativeAppWindowViews::CanResize() const { |
| 701 return resizable_ && !app_window_->size_constraints().HasFixedSize(); | 695 return resizable_ && !app_window_->size_constraints().HasFixedSize(); |
| 702 } | 696 } |
| 703 | 697 |
| 704 bool NativeAppWindowViews::CanMaximize() const { | 698 bool NativeAppWindowViews::CanMaximize() const { |
| 705 return resizable_ && !app_window_->size_constraints().HasMaximumSize() && | 699 return resizable_ && !app_window_->size_constraints().HasMaximumSize() && |
| 706 !app_window_->window_type_is_panel(); | 700 !app_window_->window_type_is_panel(); |
| 707 } | 701 } |
| 708 | 702 |
| 709 base::string16 NativeAppWindowViews::GetWindowTitle() const { | 703 base::string16 NativeAppWindowViews::GetWindowTitle() const { |
| 710 return app_window_->GetTitle(); | 704 return base::string16(); |
| 711 } | 705 } |
| 712 | 706 |
| 713 bool NativeAppWindowViews::ShouldShowWindowTitle() const { | 707 bool NativeAppWindowViews::ShouldShowWindowTitle() const { |
| 714 return app_window_->window_type() == AppWindow::WINDOW_TYPE_V1_PANEL; | 708 return app_window_->window_type() == AppWindow::WINDOW_TYPE_V1_PANEL; |
| 715 } | 709 } |
| 716 | 710 |
| 717 gfx::ImageSkia NativeAppWindowViews::GetWindowAppIcon() { | 711 gfx::ImageSkia NativeAppWindowViews::GetWindowAppIcon() { |
| 718 gfx::Image app_icon = app_window_->app_icon(); | 712 gfx::Image app_icon = app_window_->app_icon(); |
| 719 if (app_icon.IsEmpty()) | 713 if (app_icon.IsEmpty()) |
| 720 return GetWindowIcon(); | 714 return GetWindowIcon(); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 792 new ash::ImmersiveFullscreenController()); | 786 new ash::ImmersiveFullscreenController()); |
| 793 custom_frame_view->InitImmersiveFullscreenControllerForView( | 787 custom_frame_view->InitImmersiveFullscreenControllerForView( |
| 794 immersive_fullscreen_controller_.get()); | 788 immersive_fullscreen_controller_.get()); |
| 795 } | 789 } |
| 796 #endif | 790 #endif |
| 797 custom_frame_view->GetHeaderView()->set_context_menu_controller(this); | 791 custom_frame_view->GetHeaderView()->set_context_menu_controller(this); |
| 798 return custom_frame_view; | 792 return custom_frame_view; |
| 799 } | 793 } |
| 800 } | 794 } |
| 801 #endif | 795 #endif |
| 802 if (ShouldUseChromeStyleFrame()) | 796 if (!ShouldUseNativeFrame()) |
| 803 return CreateAppWindowFrameView(); | 797 return CreateAppWindowFrameView(); |
| 804 return views::WidgetDelegateView::CreateNonClientFrameView(widget); | 798 return views::WidgetDelegateView::CreateNonClientFrameView(widget); |
| 805 } | 799 } |
| 806 | 800 |
| 807 bool NativeAppWindowViews::WidgetHasHitTestMask() const { | 801 bool NativeAppWindowViews::WidgetHasHitTestMask() const { |
| 808 return shape_ != NULL; | 802 return shape_ != NULL; |
| 809 } | 803 } |
| 810 | 804 |
| 811 void NativeAppWindowViews::GetWidgetHitTestMask(gfx::Path* mask) const { | 805 void NativeAppWindowViews::GetWidgetHitTestMask(gfx::Path* mask) const { |
| 812 shape_->getBoundaryPath(mask); | 806 shape_->getBoundaryPath(mask); |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1034 void NativeAppWindowViews::HandleKeyboardEvent( | 1028 void NativeAppWindowViews::HandleKeyboardEvent( |
| 1035 const content::NativeWebKeyboardEvent& event) { | 1029 const content::NativeWebKeyboardEvent& event) { |
| 1036 unhandled_keyboard_event_handler_.HandleKeyboardEvent(event, | 1030 unhandled_keyboard_event_handler_.HandleKeyboardEvent(event, |
| 1037 GetFocusManager()); | 1031 GetFocusManager()); |
| 1038 } | 1032 } |
| 1039 | 1033 |
| 1040 bool NativeAppWindowViews::IsFrameless() const { | 1034 bool NativeAppWindowViews::IsFrameless() const { |
| 1041 return frameless_; | 1035 return frameless_; |
| 1042 } | 1036 } |
| 1043 | 1037 |
| 1038 bool NativeAppWindowViews::HasFrameColor() const { return has_frame_color_; } | |
| 1039 | |
| 1040 SkColor NativeAppWindowViews::FrameColor() const { return frame_color_; } | |
| 1041 | |
| 1044 gfx::Insets NativeAppWindowViews::GetFrameInsets() const { | 1042 gfx::Insets NativeAppWindowViews::GetFrameInsets() const { |
| 1045 if (frameless_) | 1043 if (frameless_) |
| 1046 return gfx::Insets(); | 1044 return gfx::Insets(); |
| 1047 | 1045 |
| 1048 // The pretend client_bounds passed in need to be large enough to ensure that | 1046 // The pretend client_bounds passed in need to be large enough to ensure that |
| 1049 // GetWindowBoundsForClientBounds() doesn't decide that it needs more than | 1047 // GetWindowBoundsForClientBounds() doesn't decide that it needs more than |
| 1050 // the specified amount of space to fit the window controls in, and return a | 1048 // the specified amount of space to fit the window controls in, and return a |
| 1051 // number larger than the real frame insets. Most window controls are smaller | 1049 // number larger than the real frame insets. Most window controls are smaller |
| 1052 // than 1000x1000px, so this should be big enough. | 1050 // than 1000x1000px, so this should be big enough. |
| 1053 gfx::Rect client_bounds = gfx::Rect(1000, 1000); | 1051 gfx::Rect client_bounds = gfx::Rect(1000, 1000); |
| 1054 gfx::Rect window_bounds = | 1052 gfx::Rect window_bounds = |
| 1055 window_->non_client_view()->GetWindowBoundsForClientBounds( | 1053 window_->non_client_view()->GetWindowBoundsForClientBounds( |
| 1056 client_bounds); | 1054 client_bounds); |
| 1057 return window_bounds.InsetsFrom(client_bounds); | 1055 return window_bounds.InsetsFrom(client_bounds); |
| 1058 } | 1056 } |
| 1059 | 1057 |
| 1060 void NativeAppWindowViews::HideWithApp() {} | 1058 void NativeAppWindowViews::HideWithApp() {} |
| 1061 void NativeAppWindowViews::ShowWithApp() {} | 1059 void NativeAppWindowViews::ShowWithApp() {} |
| 1062 void NativeAppWindowViews::UpdateWindowMinMaxSize() {} | 1060 void NativeAppWindowViews::UpdateWindowMinMaxSize() {} |
| OLD | NEW |