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

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

Issue 166443004: Add frame color option to packaged app windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase 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
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" 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 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 : web_view_(NULL), 204 : web_view_(NULL),
205 window_(NULL), 205 window_(NULL),
206 is_fullscreen_(false), 206 is_fullscreen_(false),
207 weak_ptr_factory_(this) { 207 weak_ptr_factory_(this) {
208 } 208 }
209 209
210 void NativeAppWindowViews::Init(apps::AppWindow* app_window, 210 void NativeAppWindowViews::Init(apps::AppWindow* app_window,
211 const AppWindow::CreateParams& create_params) { 211 const AppWindow::CreateParams& create_params) {
212 app_window_ = app_window; 212 app_window_ = app_window;
213 frameless_ = create_params.frame == AppWindow::FRAME_NONE; 213 frameless_ = create_params.frame == AppWindow::FRAME_NONE;
214 has_frame_color_ = create_params.has_frame_color;
215 frame_color_ = create_params.frame_color;
214 transparent_background_ = create_params.transparent_background; 216 transparent_background_ = create_params.transparent_background;
215 resizable_ = create_params.resizable; 217 resizable_ = create_params.resizable;
216 Observe(web_contents()); 218 Observe(web_contents());
217 219
218 window_ = new views::Widget; 220 window_ = new views::Widget;
219 if (create_params.window_type == AppWindow::WINDOW_TYPE_PANEL || 221 if (create_params.window_type == AppWindow::WINDOW_TYPE_PANEL ||
220 create_params.window_type == AppWindow::WINDOW_TYPE_V1_PANEL) { 222 create_params.window_type == AppWindow::WINDOW_TYPE_V1_PANEL) {
221 InitializePanelWindow(create_params); 223 InitializePanelWindow(create_params);
222 } else { 224 } else {
223 InitializeDefaultWindow(create_params); 225 InitializeDefaultWindow(create_params);
224 } 226 }
225 extension_keybinding_registry_.reset(new ExtensionKeybindingRegistryViews( 227 extension_keybinding_registry_.reset(new ExtensionKeybindingRegistryViews(
226 Profile::FromBrowserContext(browser_context()), 228 Profile::FromBrowserContext(browser_context()),
227 window_->GetFocusManager(), 229 window_->GetFocusManager(),
228 extensions::ExtensionKeybindingRegistry::PLATFORM_APPS_ONLY, 230 extensions::ExtensionKeybindingRegistry::PLATFORM_APPS_ONLY,
229 app_window_)); 231 app_window_));
230 232
231 OnViewWasResized(); 233 OnViewWasResized();
232 window_->AddObserver(this); 234 window_->AddObserver(this);
233 235
234 #if defined(OS_WIN) 236 #if defined(OS_WIN)
235 if (ShouldUseChromeStyleFrame() && 237 if (ShouldUseNativeFrame() &&
236 chrome::GetHostDesktopTypeForNativeWindow(window_->GetNativeWindow()) != 238 chrome::GetHostDesktopTypeForNativeWindow(window_->GetNativeWindow()) !=
237 chrome::HOST_DESKTOP_TYPE_ASH) { 239 chrome::HOST_DESKTOP_TYPE_ASH) {
238 InstallEasyResizeTargeterOnContainer(); 240 InstallEasyResizeTargeterOnContainer();
239 } 241 }
240 #endif 242 #endif
241 } 243 }
242 244
243 NativeAppWindowViews::~NativeAppWindowViews() { 245 NativeAppWindowViews::~NativeAppWindowViews() {
244 web_view_->SetWebContents(NULL); 246 web_view_->SetWebContents(NULL);
245 } 247 }
246 248
247 void NativeAppWindowViews::OnBeforeWidgetInit( 249 void NativeAppWindowViews::OnBeforeWidgetInit(
248 views::Widget::InitParams* init_params, 250 views::Widget::InitParams* init_params,
249 views::Widget* widget) {} 251 views::Widget* widget) {}
250 252
251 void NativeAppWindowViews::InitializeDefaultWindow( 253 void NativeAppWindowViews::InitializeDefaultWindow(
252 const AppWindow::CreateParams& create_params) { 254 const AppWindow::CreateParams& create_params) {
253 std::string app_name = 255 std::string app_name =
254 web_app::GenerateApplicationNameFromExtensionId(extension()->id()); 256 web_app::GenerateApplicationNameFromExtensionId(extension()->id());
255 257
256 views::Widget::InitParams init_params(views::Widget::InitParams::TYPE_WINDOW); 258 views::Widget::InitParams init_params(views::Widget::InitParams::TYPE_WINDOW);
257 init_params.delegate = this; 259 init_params.delegate = this;
258 init_params.remove_standard_frame = ShouldUseChromeStyleFrame(); 260 init_params.remove_standard_frame = !ShouldUseNativeFrame();
259 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) 261 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
260 // On Linux, remove the standard frame. Instead, we will use CustomFrameView 262 // On Linux, remove the standard frame. Instead, we will use CustomFrameView
261 // to draw a native-like frame. 263 // to draw a native-like frame.
262 // TODO(mgiuca): Remove this during fix for http://crbug.com/322256. 264 // TODO(mgiuca): Remove this during fix for http://crbug.com/322256.
263 init_params.remove_standard_frame = true; 265 init_params.remove_standard_frame = true;
264 #endif 266 #endif
265 init_params.use_system_default_icon = true; 267 init_params.use_system_default_icon = true;
266 // TODO(erg): Conceptually, these are toplevel windows, but we theoretically 268 // TODO(erg): Conceptually, these are toplevel windows, but we theoretically
267 // could plumb context through to here in some cases. 269 // could plumb context through to here in some cases.
268 init_params.top_level = true; 270 init_params.top_level = true;
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 native_window->GetRootWindow(), 371 native_window->GetRootWindow(),
370 native_window->GetBoundsInScreen()); 372 native_window->GetBoundsInScreen());
371 window_->SetBounds(window_bounds); 373 window_->SetBounds(window_bounds);
372 } 374 }
373 #else 375 #else
374 // TODO(stevenjb): NativeAppWindow panels need to be implemented for other 376 // TODO(stevenjb): NativeAppWindow panels need to be implemented for other
375 // platforms. 377 // platforms.
376 #endif 378 #endif
377 } 379 }
378 380
379 bool NativeAppWindowViews::ShouldUseChromeStyleFrame() const { 381 bool NativeAppWindowViews::ShouldUseNativeFrame() const {
380 if (frameless_) 382 return !frameless_ & !has_frame_color_;
381 return true;
382
383 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
384 // Linux always uses native style frames.
385 return false;
386 #endif
387
388 return !CommandLine::ForCurrentProcess()->HasSwitch(
389 switches::kAppsUseNativeFrame);
390 } 383 }
391 384
392 void NativeAppWindowViews::InstallEasyResizeTargeterOnContainer() const { 385 void NativeAppWindowViews::InstallEasyResizeTargeterOnContainer() const {
393 aura::Window* root_window = window_->GetNativeWindow()->GetRootWindow(); 386 aura::Window* root_window = window_->GetNativeWindow()->GetRootWindow();
394 gfx::Insets inset(kResizeInsideBoundsSize, kResizeInsideBoundsSize, 387 gfx::Insets inset(kResizeInsideBoundsSize, kResizeInsideBoundsSize,
395 kResizeInsideBoundsSize, kResizeInsideBoundsSize); 388 kResizeInsideBoundsSize, kResizeInsideBoundsSize);
396 root_window->SetEventTargeter(scoped_ptr<ui::EventTargeter>( 389 root_window->SetEventTargeter(scoped_ptr<ui::EventTargeter>(
397 new wm::EasyResizeWindowTargeter(root_window, inset, inset))); 390 new wm::EasyResizeWindowTargeter(root_window, inset, inset)));
398 } 391 }
399 392
400 apps::AppWindowFrameView* NativeAppWindowViews::CreateAppWindowFrameView() { 393 apps::AppWindowFrameView* NativeAppWindowViews::CreateAppWindowFrameView() {
401 // By default the user can resize the window from slightly inside the bounds. 394 // By default the user can resize the window from slightly inside the bounds.
402 int resize_inside_bounds_size = kResizeInsideBoundsSize; 395 int resize_inside_bounds_size = kResizeInsideBoundsSize;
403 int resize_outside_bounds_size = 0; 396 int resize_outside_bounds_size = 0;
404 int resize_outside_scale_for_touch = 1; 397 int resize_outside_scale_for_touch = 1;
405 int resize_area_corner_size = kResizeAreaCornerSize; 398 int resize_area_corner_size = kResizeAreaCornerSize;
406 #if defined(USE_ASH) 399 #if defined(USE_ASH)
407 // For Aura windows on the Ash desktop the sizes are different and the user 400 // For Aura windows on the Ash desktop the sizes are different and the user
408 // can resize the window from slightly outside the bounds as well. 401 // can resize the window from slightly outside the bounds as well.
409 if (chrome::IsNativeWindowInAsh(window_->GetNativeWindow())) { 402 if (chrome::IsNativeWindowInAsh(window_->GetNativeWindow())) {
410 resize_inside_bounds_size = ash::kResizeInsideBoundsSize; 403 resize_inside_bounds_size = ash::kResizeInsideBoundsSize;
411 resize_outside_bounds_size = ash::kResizeOutsideBoundsSize; 404 resize_outside_bounds_size = ash::kResizeOutsideBoundsSize;
412 resize_outside_scale_for_touch = ash::kResizeOutsideBoundsScaleForTouch; 405 resize_outside_scale_for_touch = ash::kResizeOutsideBoundsScaleForTouch;
413 resize_area_corner_size = ash::kResizeAreaCornerSize; 406 resize_area_corner_size = ash::kResizeAreaCornerSize;
414 } 407 }
415 #endif 408 #endif
416 apps::AppWindowFrameView* frame_view = new apps::AppWindowFrameView(this); 409 apps::AppWindowFrameView* frame_view = new apps::AppWindowFrameView(this);
417 frame_view->Init(window_, 410 frame_view->Init(window_,
411 frame_color_,
418 resize_inside_bounds_size, 412 resize_inside_bounds_size,
419 resize_outside_bounds_size, 413 resize_outside_bounds_size,
420 resize_outside_scale_for_touch, 414 resize_outside_scale_for_touch,
421 resize_area_corner_size); 415 resize_area_corner_size);
422 return frame_view; 416 return frame_view;
423 } 417 }
424 418
425 // ui::BaseWindow implementation. 419 // ui::BaseWindow implementation.
426 420
427 bool NativeAppWindowViews::IsActive() const { 421 bool NativeAppWindowViews::IsActive() const {
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 bool NativeAppWindowViews::CanResize() const { 625 bool NativeAppWindowViews::CanResize() const {
632 return resizable_ && !app_window_->size_constraints().HasFixedSize(); 626 return resizable_ && !app_window_->size_constraints().HasFixedSize();
633 } 627 }
634 628
635 bool NativeAppWindowViews::CanMaximize() const { 629 bool NativeAppWindowViews::CanMaximize() const {
636 return resizable_ && !app_window_->size_constraints().HasMaximumSize() && 630 return resizable_ && !app_window_->size_constraints().HasMaximumSize() &&
637 !app_window_->window_type_is_panel(); 631 !app_window_->window_type_is_panel();
638 } 632 }
639 633
640 base::string16 NativeAppWindowViews::GetWindowTitle() const { 634 base::string16 NativeAppWindowViews::GetWindowTitle() const {
641 return app_window_->GetTitle(); 635 return base::string16();
642 } 636 }
643 637
644 bool NativeAppWindowViews::ShouldShowWindowTitle() const { 638 bool NativeAppWindowViews::ShouldShowWindowTitle() const {
645 return app_window_->window_type() == AppWindow::WINDOW_TYPE_V1_PANEL; 639 return app_window_->window_type() == AppWindow::WINDOW_TYPE_V1_PANEL;
646 } 640 }
647 641
648 gfx::ImageSkia NativeAppWindowViews::GetWindowAppIcon() { 642 gfx::ImageSkia NativeAppWindowViews::GetWindowAppIcon() {
649 gfx::Image app_icon = app_window_->app_icon(); 643 gfx::Image app_icon = app_window_->app_icon();
650 if (app_icon.IsEmpty()) 644 if (app_icon.IsEmpty())
651 return GetWindowIcon(); 645 return GetWindowIcon();
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
723 new ash::ImmersiveFullscreenController()); 717 new ash::ImmersiveFullscreenController());
724 custom_frame_view->InitImmersiveFullscreenControllerForView( 718 custom_frame_view->InitImmersiveFullscreenControllerForView(
725 immersive_fullscreen_controller_.get()); 719 immersive_fullscreen_controller_.get());
726 } 720 }
727 #endif 721 #endif
728 custom_frame_view->GetHeaderView()->set_context_menu_controller(this); 722 custom_frame_view->GetHeaderView()->set_context_menu_controller(this);
729 return custom_frame_view; 723 return custom_frame_view;
730 } 724 }
731 } 725 }
732 #endif 726 #endif
733 if (ShouldUseChromeStyleFrame()) 727 if (!ShouldUseNativeFrame())
734 return CreateAppWindowFrameView(); 728 return CreateAppWindowFrameView();
735 return views::WidgetDelegateView::CreateNonClientFrameView(widget); 729 return views::WidgetDelegateView::CreateNonClientFrameView(widget);
736 } 730 }
737 731
738 bool NativeAppWindowViews::WidgetHasHitTestMask() const { 732 bool NativeAppWindowViews::WidgetHasHitTestMask() const {
739 return shape_ != NULL; 733 return shape_ != NULL;
740 } 734 }
741 735
742 void NativeAppWindowViews::GetWidgetHitTestMask(gfx::Path* mask) const { 736 void NativeAppWindowViews::GetWidgetHitTestMask(gfx::Path* mask) const {
743 shape_->getBoundaryPath(mask); 737 shape_->getBoundaryPath(mask);
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
965 void NativeAppWindowViews::HandleKeyboardEvent( 959 void NativeAppWindowViews::HandleKeyboardEvent(
966 const content::NativeWebKeyboardEvent& event) { 960 const content::NativeWebKeyboardEvent& event) {
967 unhandled_keyboard_event_handler_.HandleKeyboardEvent(event, 961 unhandled_keyboard_event_handler_.HandleKeyboardEvent(event,
968 GetFocusManager()); 962 GetFocusManager());
969 } 963 }
970 964
971 bool NativeAppWindowViews::IsFrameless() const { 965 bool NativeAppWindowViews::IsFrameless() const {
972 return frameless_; 966 return frameless_;
973 } 967 }
974 968
969 bool NativeAppWindowViews::HasFrameColor() const { return has_frame_color_; }
970
971 SkColor NativeAppWindowViews::FrameColor() const { return frame_color_; }
972
975 gfx::Insets NativeAppWindowViews::GetFrameInsets() const { 973 gfx::Insets NativeAppWindowViews::GetFrameInsets() const {
976 if (frameless_) 974 if (frameless_)
977 return gfx::Insets(); 975 return gfx::Insets();
978 976
979 // The pretend client_bounds passed in need to be large enough to ensure that 977 // The pretend client_bounds passed in need to be large enough to ensure that
980 // GetWindowBoundsForClientBounds() doesn't decide that it needs more than 978 // GetWindowBoundsForClientBounds() doesn't decide that it needs more than
981 // the specified amount of space to fit the window controls in, and return a 979 // the specified amount of space to fit the window controls in, and return a
982 // number larger than the real frame insets. Most window controls are smaller 980 // number larger than the real frame insets. Most window controls are smaller
983 // than 1000x1000px, so this should be big enough. 981 // than 1000x1000px, so this should be big enough.
984 gfx::Rect client_bounds = gfx::Rect(1000, 1000); 982 gfx::Rect client_bounds = gfx::Rect(1000, 1000);
985 gfx::Rect window_bounds = 983 gfx::Rect window_bounds =
986 window_->non_client_view()->GetWindowBoundsForClientBounds( 984 window_->non_client_view()->GetWindowBoundsForClientBounds(
987 client_bounds); 985 client_bounds);
988 return window_bounds.InsetsFrom(client_bounds); 986 return window_bounds.InsetsFrom(client_bounds);
989 } 987 }
990 988
991 void NativeAppWindowViews::HideWithApp() {} 989 void NativeAppWindowViews::HideWithApp() {}
992 void NativeAppWindowViews::ShowWithApp() {} 990 void NativeAppWindowViews::ShowWithApp() {}
993 void NativeAppWindowViews::UpdateWindowMinMaxSize() {} 991 void NativeAppWindowViews::UpdateWindowMinMaxSize() {}
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/apps/native_app_window_views.h ('k') | chrome/common/extensions/api/app_window.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698