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/threading/sequenced_worker_pool.h" | 10 #include "base/threading/sequenced_worker_pool.h" |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 : web_view_(NULL), | 203 : web_view_(NULL), |
204 window_(NULL), | 204 window_(NULL), |
205 is_fullscreen_(false), | 205 is_fullscreen_(false), |
206 weak_ptr_factory_(this) { | 206 weak_ptr_factory_(this) { |
207 } | 207 } |
208 | 208 |
209 void NativeAppWindowViews::Init(apps::AppWindow* app_window, | 209 void NativeAppWindowViews::Init(apps::AppWindow* app_window, |
210 const AppWindow::CreateParams& create_params) { | 210 const AppWindow::CreateParams& create_params) { |
211 app_window_ = app_window; | 211 app_window_ = app_window; |
212 frameless_ = create_params.frame == AppWindow::FRAME_NONE; | 212 frameless_ = create_params.frame == AppWindow::FRAME_NONE; |
| 213 has_frame_color_ = create_params.has_frame_color; |
| 214 frame_color_ = create_params.frame_color; |
213 transparent_background_ = create_params.transparent_background; | 215 transparent_background_ = create_params.transparent_background; |
214 resizable_ = create_params.resizable; | 216 resizable_ = create_params.resizable; |
215 Observe(web_contents()); | 217 Observe(web_contents()); |
216 | 218 |
217 window_ = new views::Widget; | 219 window_ = new views::Widget; |
218 if (create_params.window_type == AppWindow::WINDOW_TYPE_PANEL || | 220 if (create_params.window_type == AppWindow::WINDOW_TYPE_PANEL || |
219 create_params.window_type == AppWindow::WINDOW_TYPE_V1_PANEL) { | 221 create_params.window_type == AppWindow::WINDOW_TYPE_V1_PANEL) { |
220 InitializePanelWindow(create_params); | 222 InitializePanelWindow(create_params); |
221 } else { | 223 } else { |
222 InitializeDefaultWindow(create_params); | 224 InitializeDefaultWindow(create_params); |
(...skipping 16 matching lines...) Expand all Loading... |
239 views::Widget::InitParams* init_params, | 241 views::Widget::InitParams* init_params, |
240 views::Widget* widget) {} | 242 views::Widget* widget) {} |
241 | 243 |
242 void NativeAppWindowViews::InitializeDefaultWindow( | 244 void NativeAppWindowViews::InitializeDefaultWindow( |
243 const AppWindow::CreateParams& create_params) { | 245 const AppWindow::CreateParams& create_params) { |
244 std::string app_name = | 246 std::string app_name = |
245 web_app::GenerateApplicationNameFromExtensionId(extension()->id()); | 247 web_app::GenerateApplicationNameFromExtensionId(extension()->id()); |
246 | 248 |
247 views::Widget::InitParams init_params(views::Widget::InitParams::TYPE_WINDOW); | 249 views::Widget::InitParams init_params(views::Widget::InitParams::TYPE_WINDOW); |
248 init_params.delegate = this; | 250 init_params.delegate = this; |
249 init_params.remove_standard_frame = ShouldUseChromeStyleFrame(); | 251 init_params.remove_standard_frame = !ShouldUseNativeFrame(); |
250 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 252 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
251 // On Linux, remove the standard frame. Instead, we will use CustomFrameView | 253 // On Linux, remove the standard frame. Instead, we will use CustomFrameView |
252 // to draw a native-like frame. | 254 // to draw a native-like frame. |
253 // TODO(mgiuca): Remove this during fix for http://crbug.com/322256. | 255 // TODO(mgiuca): Remove this during fix for http://crbug.com/322256. |
254 init_params.remove_standard_frame = true; | 256 init_params.remove_standard_frame = true; |
255 #endif | 257 #endif |
256 init_params.use_system_default_icon = true; | 258 init_params.use_system_default_icon = true; |
257 // TODO(erg): Conceptually, these are toplevel windows, but we theoretically | 259 // TODO(erg): Conceptually, these are toplevel windows, but we theoretically |
258 // could plumb context through to here in some cases. | 260 // could plumb context through to here in some cases. |
259 init_params.top_level = true; | 261 init_params.top_level = true; |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 native_window->GetRootWindow(), | 362 native_window->GetRootWindow(), |
361 native_window->GetBoundsInScreen()); | 363 native_window->GetBoundsInScreen()); |
362 window_->SetBounds(window_bounds); | 364 window_->SetBounds(window_bounds); |
363 } | 365 } |
364 #else | 366 #else |
365 // TODO(stevenjb): NativeAppWindow panels need to be implemented for other | 367 // TODO(stevenjb): NativeAppWindow panels need to be implemented for other |
366 // platforms. | 368 // platforms. |
367 #endif | 369 #endif |
368 } | 370 } |
369 | 371 |
370 bool NativeAppWindowViews::ShouldUseChromeStyleFrame() const { | 372 bool NativeAppWindowViews::ShouldUseNativeFrame() const { |
371 if (frameless_) | 373 return !frameless_ & !has_frame_color_; |
372 return true; | |
373 | |
374 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | |
375 // Linux always uses native style frames. | |
376 return false; | |
377 #endif | |
378 | |
379 return !CommandLine::ForCurrentProcess()->HasSwitch( | |
380 switches::kAppsUseNativeFrame); | |
381 } | 374 } |
382 | 375 |
383 apps::AppWindowFrameView* NativeAppWindowViews::CreateAppWindowFrameView() { | 376 apps::AppWindowFrameView* NativeAppWindowViews::CreateAppWindowFrameView() { |
384 // By default the user can resize the window from slightly inside the bounds. | 377 // By default the user can resize the window from slightly inside the bounds. |
385 int resize_inside_bounds_size = kResizeInsideBoundsSize; | 378 int resize_inside_bounds_size = kResizeInsideBoundsSize; |
386 int resize_outside_bounds_size = 0; | 379 int resize_outside_bounds_size = 0; |
387 int resize_outside_scale_for_touch = 1; | 380 int resize_outside_scale_for_touch = 1; |
388 int resize_area_corner_size = kResizeAreaCornerSize; | 381 int resize_area_corner_size = kResizeAreaCornerSize; |
389 #if defined(USE_ASH) | 382 #if defined(USE_ASH) |
390 // For Aura windows on the Ash desktop the sizes are different and the user | 383 // 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. | 384 // can resize the window from slightly outside the bounds as well. |
392 if (chrome::IsNativeWindowInAsh(window_->GetNativeWindow())) { | 385 if (chrome::IsNativeWindowInAsh(window_->GetNativeWindow())) { |
393 resize_inside_bounds_size = ash::kResizeInsideBoundsSize; | 386 resize_inside_bounds_size = ash::kResizeInsideBoundsSize; |
394 resize_outside_bounds_size = ash::kResizeOutsideBoundsSize; | 387 resize_outside_bounds_size = ash::kResizeOutsideBoundsSize; |
395 resize_outside_scale_for_touch = ash::kResizeOutsideBoundsScaleForTouch; | 388 resize_outside_scale_for_touch = ash::kResizeOutsideBoundsScaleForTouch; |
396 resize_area_corner_size = ash::kResizeAreaCornerSize; | 389 resize_area_corner_size = ash::kResizeAreaCornerSize; |
397 } | 390 } |
398 #endif | 391 #endif |
399 apps::AppWindowFrameView* frame_view = new apps::AppWindowFrameView(this); | 392 apps::AppWindowFrameView* frame_view = new apps::AppWindowFrameView(this); |
400 frame_view->Init(window_, | 393 frame_view->Init(window_, |
| 394 frame_color_, |
401 resize_inside_bounds_size, | 395 resize_inside_bounds_size, |
402 resize_outside_bounds_size, | 396 resize_outside_bounds_size, |
403 resize_outside_scale_for_touch, | 397 resize_outside_scale_for_touch, |
404 resize_area_corner_size); | 398 resize_area_corner_size); |
405 return frame_view; | 399 return frame_view; |
406 } | 400 } |
407 | 401 |
408 // ui::BaseWindow implementation. | 402 // ui::BaseWindow implementation. |
409 | 403 |
410 bool NativeAppWindowViews::IsActive() const { | 404 bool NativeAppWindowViews::IsActive() const { |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
614 bool NativeAppWindowViews::CanResize() const { | 608 bool NativeAppWindowViews::CanResize() const { |
615 return resizable_ && !app_window_->size_constraints().HasFixedSize(); | 609 return resizable_ && !app_window_->size_constraints().HasFixedSize(); |
616 } | 610 } |
617 | 611 |
618 bool NativeAppWindowViews::CanMaximize() const { | 612 bool NativeAppWindowViews::CanMaximize() const { |
619 return resizable_ && !app_window_->size_constraints().HasMaximumSize() && | 613 return resizable_ && !app_window_->size_constraints().HasMaximumSize() && |
620 !app_window_->window_type_is_panel(); | 614 !app_window_->window_type_is_panel(); |
621 } | 615 } |
622 | 616 |
623 base::string16 NativeAppWindowViews::GetWindowTitle() const { | 617 base::string16 NativeAppWindowViews::GetWindowTitle() const { |
624 return app_window_->GetTitle(); | 618 return base::string16(); |
625 } | 619 } |
626 | 620 |
627 bool NativeAppWindowViews::ShouldShowWindowTitle() const { | 621 bool NativeAppWindowViews::ShouldShowWindowTitle() const { |
628 return app_window_->window_type() == AppWindow::WINDOW_TYPE_V1_PANEL; | 622 return app_window_->window_type() == AppWindow::WINDOW_TYPE_V1_PANEL; |
629 } | 623 } |
630 | 624 |
631 gfx::ImageSkia NativeAppWindowViews::GetWindowAppIcon() { | 625 gfx::ImageSkia NativeAppWindowViews::GetWindowAppIcon() { |
632 gfx::Image app_icon = app_window_->app_icon(); | 626 gfx::Image app_icon = app_window_->app_icon(); |
633 if (app_icon.IsEmpty()) | 627 if (app_icon.IsEmpty()) |
634 return GetWindowIcon(); | 628 return GetWindowIcon(); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
706 new ash::ImmersiveFullscreenController()); | 700 new ash::ImmersiveFullscreenController()); |
707 custom_frame_view->InitImmersiveFullscreenControllerForView( | 701 custom_frame_view->InitImmersiveFullscreenControllerForView( |
708 immersive_fullscreen_controller_.get()); | 702 immersive_fullscreen_controller_.get()); |
709 } | 703 } |
710 #endif | 704 #endif |
711 custom_frame_view->GetHeaderView()->set_context_menu_controller(this); | 705 custom_frame_view->GetHeaderView()->set_context_menu_controller(this); |
712 return custom_frame_view; | 706 return custom_frame_view; |
713 } | 707 } |
714 } | 708 } |
715 #endif | 709 #endif |
716 if (ShouldUseChromeStyleFrame()) | 710 if (!ShouldUseNativeFrame()) |
717 return CreateAppWindowFrameView(); | 711 return CreateAppWindowFrameView(); |
718 return views::WidgetDelegateView::CreateNonClientFrameView(widget); | 712 return views::WidgetDelegateView::CreateNonClientFrameView(widget); |
719 } | 713 } |
720 | 714 |
721 bool NativeAppWindowViews::WidgetHasHitTestMask() const { | 715 bool NativeAppWindowViews::WidgetHasHitTestMask() const { |
722 return shape_ != NULL; | 716 return shape_ != NULL; |
723 } | 717 } |
724 | 718 |
725 void NativeAppWindowViews::GetWidgetHitTestMask(gfx::Path* mask) const { | 719 void NativeAppWindowViews::GetWidgetHitTestMask(gfx::Path* mask) const { |
726 shape_->getBoundaryPath(mask); | 720 shape_->getBoundaryPath(mask); |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
948 void NativeAppWindowViews::HandleKeyboardEvent( | 942 void NativeAppWindowViews::HandleKeyboardEvent( |
949 const content::NativeWebKeyboardEvent& event) { | 943 const content::NativeWebKeyboardEvent& event) { |
950 unhandled_keyboard_event_handler_.HandleKeyboardEvent(event, | 944 unhandled_keyboard_event_handler_.HandleKeyboardEvent(event, |
951 GetFocusManager()); | 945 GetFocusManager()); |
952 } | 946 } |
953 | 947 |
954 bool NativeAppWindowViews::IsFrameless() const { | 948 bool NativeAppWindowViews::IsFrameless() const { |
955 return frameless_; | 949 return frameless_; |
956 } | 950 } |
957 | 951 |
| 952 bool NativeAppWindowViews::HasFrameColor() const { return has_frame_color_; } |
| 953 |
| 954 SkColor NativeAppWindowViews::FrameColor() const { return frame_color_; } |
| 955 |
958 gfx::Insets NativeAppWindowViews::GetFrameInsets() const { | 956 gfx::Insets NativeAppWindowViews::GetFrameInsets() const { |
959 if (frameless_) | 957 if (frameless_) |
960 return gfx::Insets(); | 958 return gfx::Insets(); |
961 | 959 |
962 // The pretend client_bounds passed in need to be large enough to ensure that | 960 // The pretend client_bounds passed in need to be large enough to ensure that |
963 // GetWindowBoundsForClientBounds() doesn't decide that it needs more than | 961 // GetWindowBoundsForClientBounds() doesn't decide that it needs more than |
964 // the specified amount of space to fit the window controls in, and return a | 962 // 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 | 963 // number larger than the real frame insets. Most window controls are smaller |
966 // than 1000x1000px, so this should be big enough. | 964 // than 1000x1000px, so this should be big enough. |
967 gfx::Rect client_bounds = gfx::Rect(1000, 1000); | 965 gfx::Rect client_bounds = gfx::Rect(1000, 1000); |
968 gfx::Rect window_bounds = | 966 gfx::Rect window_bounds = |
969 window_->non_client_view()->GetWindowBoundsForClientBounds( | 967 window_->non_client_view()->GetWindowBoundsForClientBounds( |
970 client_bounds); | 968 client_bounds); |
971 return window_bounds.InsetsFrom(client_bounds); | 969 return window_bounds.InsetsFrom(client_bounds); |
972 } | 970 } |
973 | 971 |
974 void NativeAppWindowViews::HideWithApp() {} | 972 void NativeAppWindowViews::HideWithApp() {} |
975 void NativeAppWindowViews::ShowWithApp() {} | 973 void NativeAppWindowViews::ShowWithApp() {} |
976 void NativeAppWindowViews::UpdateWindowMinMaxSize() {} | 974 void NativeAppWindowViews::UpdateWindowMinMaxSize() {} |
OLD | NEW |