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

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

Issue 949553002: Start using the controller in app's view. Base URL: https://chromium.googlesource.com/chromium/src.git@fsRefactor
Patch Set: Created 5 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/chrome_native_app_window_views.h" 5 #include "chrome/browser/ui/views/apps/chrome_native_app_window_views.h"
6 6
7 #include "apps/ui/views/app_window_frame_view.h" 7 #include "apps/ui/views/app_window_frame_view.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "chrome/app/chrome_command_ids.h" 9 #include "chrome/app/chrome_command_ids.h"
10 #include "chrome/browser/app_mode/app_mode_utils.h" 10 #include "chrome/browser/app_mode/app_mode_utils.h"
11 #include "chrome/browser/favicon/favicon_tab_helper.h" 11 #include "chrome/browser/favicon/favicon_tab_helper.h"
12 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/ui/exclusive_access/exclusive_access_manager.h"
14 #include "chrome/browser/ui/exclusive_access/mouse_lock_controller.h"
13 #include "chrome/browser/ui/host_desktop.h" 15 #include "chrome/browser/ui/host_desktop.h"
14 #include "chrome/browser/ui/views/apps/desktop_keyboard_capture.h" 16 #include "chrome/browser/ui/views/apps/desktop_keyboard_capture.h"
15 #include "chrome/browser/ui/views/apps/shaped_app_window_targeter.h" 17 #include "chrome/browser/ui/views/apps/shaped_app_window_targeter.h"
18 #include "chrome/browser/ui/views/exclusive_access_bubble_views.h"
16 #include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views .h" 19 #include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views .h"
17 #include "chrome/browser/ui/views/frame/taskbar_decorator.h" 20 #include "chrome/browser/ui/views/frame/taskbar_decorator.h"
18 #include "chrome/browser/web_applications/web_app.h" 21 #include "chrome/browser/web_applications/web_app.h"
19 #include "chrome/common/chrome_switches.h" 22 #include "chrome/common/chrome_switches.h"
20 #include "components/ui/zoom/page_zoom.h" 23 #include "components/ui/zoom/page_zoom.h"
21 #include "components/ui/zoom/zoom_controller.h" 24 #include "components/ui/zoom/zoom_controller.h"
25 #include "content/public/browser/native_web_keyboard_event.h"
22 #include "extensions/common/extension.h" 26 #include "extensions/common/extension.h"
23 #include "ui/aura/window.h" 27 #include "ui/aura/window.h"
24 #include "ui/base/hit_test.h" 28 #include "ui/base/hit_test.h"
25 #include "ui/base/models/simple_menu_model.h" 29 #include "ui/base/models/simple_menu_model.h"
26 #include "ui/gfx/image/image_skia.h" 30 #include "ui/gfx/image/image_skia.h"
27 #include "ui/views/controls/menu/menu_runner.h" 31 #include "ui/views/controls/menu/menu_runner.h"
28 #include "ui/views/controls/webview/webview.h" 32 #include "ui/views/controls/webview/webview.h"
29 #include "ui/views/widget/widget.h" 33 #include "ui/views/widget/widget.h"
30 #include "ui/wm/core/easy_resize_window_targeter.h" 34 #include "ui/wm/core/easy_resize_window_targeter.h"
31 #include "ui/wm/core/shadow_types.h" 35 #include "ui/wm/core/shadow_types.h"
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 DISALLOW_COPY_AND_ASSIGN(NativeAppWindowStateDelegate); 196 DISALLOW_COPY_AND_ASSIGN(NativeAppWindowStateDelegate);
193 }; 197 };
194 #endif // USE_ASH 198 #endif // USE_ASH
195 199
196 } // namespace 200 } // namespace
197 201
198 ChromeNativeAppWindowViews::ChromeNativeAppWindowViews() 202 ChromeNativeAppWindowViews::ChromeNativeAppWindowViews()
199 : is_fullscreen_(false), 203 : is_fullscreen_(false),
200 has_frame_color_(false), 204 has_frame_color_(false),
201 active_frame_color_(SK_ColorBLACK), 205 active_frame_color_(SK_ColorBLACK),
202 inactive_frame_color_(SK_ColorBLACK) { 206 inactive_frame_color_(SK_ColorBLACK),
207 key_capture_requested_(false) {
208 exclusive_access_manager_.reset(new ExclusiveAccessManager(this));
203 } 209 }
204 210
205 ChromeNativeAppWindowViews::~ChromeNativeAppWindowViews() {} 211 ChromeNativeAppWindowViews::~ChromeNativeAppWindowViews() {}
206 212
207 void ChromeNativeAppWindowViews::OnBeforeWidgetInit( 213 void ChromeNativeAppWindowViews::OnBeforeWidgetInit(
208 views::Widget::InitParams* init_params, 214 views::Widget::InitParams* init_params,
209 views::Widget* widget) {} 215 views::Widget* widget) {}
210 216
211 void ChromeNativeAppWindowViews::InitializeDefaultWindow( 217 void ChromeNativeAppWindowViews::InitializeDefaultWindow(
212 const AppWindow::CreateParams& create_params) { 218 const AppWindow::CreateParams& create_params) {
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 // root window does not have a delegate, which is needed to handle the event 384 // root window does not have a delegate, which is needed to handle the event
379 // in Linux. 385 // in Linux.
380 window->SetEventTargeter(scoped_ptr<ui::EventTargeter>( 386 window->SetEventTargeter(scoped_ptr<ui::EventTargeter>(
381 new wm::EasyResizeWindowTargeter(window, inset, inset))); 387 new wm::EasyResizeWindowTargeter(window, inset, inset)));
382 } 388 }
383 #endif 389 #endif
384 390
385 return frame; 391 return frame;
386 } 392 }
387 393
394 void ChromeNativeAppWindowViews::Activate() {
395 NativeAppWindowViews::Activate();
396 exclusive_access_manager_->OnTabDetachedFromView(GetActiveWebContents());
397 }
398
399 void ChromeNativeAppWindowViews::Deactivate() {
400 NativeAppWindowViews::Deactivate();
401 exclusive_access_manager_->OnTabDeactivated(GetActiveWebContents());
402 }
403
404 bool ChromeNativeAppWindowViews::PreHandleKeyboardEvent(
405 content::WebContents* source,
406 const content::NativeWebKeyboardEvent& event,
407 bool* is_keyboard_shortcut) {
408 if (event.windowsKeyCode == ui::VKEY_ESCAPE &&
409 exclusive_access_manager_->HandleUserPressedEscape()) {
410 return true;
411 }
412 return NativeAppWindowViews::PreHandleKeyboardEvent(source, event,
413 is_keyboard_shortcut);
414 }
415
388 // ui::BaseWindow implementation. 416 // ui::BaseWindow implementation.
389 417
390 gfx::Rect ChromeNativeAppWindowViews::GetRestoredBounds() const { 418 gfx::Rect ChromeNativeAppWindowViews::GetRestoredBounds() const {
391 #if defined(USE_ASH) 419 #if defined(USE_ASH)
392 gfx::Rect* bounds = widget()->GetNativeWindow()->GetProperty( 420 gfx::Rect* bounds = widget()->GetNativeWindow()->GetProperty(
393 ash::kRestoreBoundsOverrideKey); 421 ash::kRestoreBoundsOverrideKey);
394 if (bounds && !bounds->IsEmpty()) 422 if (bounds && !bounds->IsEmpty())
395 return *bounds; 423 return *bounds;
396 #endif 424 #endif
397 return widget()->GetRestoredBounds(); 425 return widget()->GetRestoredBounds();
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 706
679 SkColor ChromeNativeAppWindowViews::ActiveFrameColor() const { 707 SkColor ChromeNativeAppWindowViews::ActiveFrameColor() const {
680 return active_frame_color_; 708 return active_frame_color_;
681 } 709 }
682 710
683 SkColor ChromeNativeAppWindowViews::InactiveFrameColor() const { 711 SkColor ChromeNativeAppWindowViews::InactiveFrameColor() const {
684 return inactive_frame_color_; 712 return inactive_frame_color_;
685 } 713 }
686 714
687 void ChromeNativeAppWindowViews::SetInterceptAllKeys(bool want_all_keys) { 715 void ChromeNativeAppWindowViews::SetInterceptAllKeys(bool want_all_keys) {
688 if (want_all_keys && (desktop_keyboard_capture_.get() == NULL)) { 716 // Noop if there is no state change.
689 desktop_keyboard_capture_.reset(new DesktopKeyboardCapture(widget())); 717 if (want_all_keys == key_capture_requested_) {
690 } else if (!want_all_keys) { 718 return;
691 desktop_keyboard_capture_.reset(NULL); 719 }
720
721 key_capture_requested_ = want_all_keys;
722 if (want_all_keys) {
723 exclusive_access_manager_->mouse_lock_controller()->RequestToLockMouse(
724 GetActiveWebContents(), true, true);
725 } else {
726 desktop_keyboard_capture_.reset(nullptr);
727 exclusive_access_manager_->mouse_lock_controller()->LostMouseLock();
692 } 728 }
693 } 729 }
694 730
695 // NativeAppWindowViews implementation. 731 // NativeAppWindowViews implementation.
696 732
697 void ChromeNativeAppWindowViews::InitializeWindow( 733 void ChromeNativeAppWindowViews::InitializeWindow(
698 AppWindow* app_window, 734 AppWindow* app_window,
699 const AppWindow::CreateParams& create_params) { 735 const AppWindow::CreateParams& create_params) {
700 DCHECK(widget()); 736 DCHECK(widget());
701 has_frame_color_ = create_params.has_frame_color; 737 has_frame_color_ = create_params.has_frame_color;
702 active_frame_color_ = create_params.active_frame_color; 738 active_frame_color_ = create_params.active_frame_color;
703 inactive_frame_color_ = create_params.inactive_frame_color; 739 inactive_frame_color_ = create_params.inactive_frame_color;
704 if (create_params.window_type == AppWindow::WINDOW_TYPE_PANEL || 740 if (create_params.window_type == AppWindow::WINDOW_TYPE_PANEL ||
705 create_params.window_type == AppWindow::WINDOW_TYPE_V1_PANEL) { 741 create_params.window_type == AppWindow::WINDOW_TYPE_V1_PANEL) {
706 InitializePanelWindow(create_params); 742 InitializePanelWindow(create_params);
707 } else { 743 } else {
708 InitializeDefaultWindow(create_params); 744 InitializeDefaultWindow(create_params);
709 } 745 }
710 extension_keybinding_registry_.reset(new ExtensionKeybindingRegistryViews( 746 extension_keybinding_registry_.reset(new ExtensionKeybindingRegistryViews(
711 Profile::FromBrowserContext(app_window->browser_context()), 747 Profile::FromBrowserContext(app_window->browser_context()),
712 widget()->GetFocusManager(), 748 widget()->GetFocusManager(),
713 extensions::ExtensionKeybindingRegistry::PLATFORM_APPS_ONLY, 749 extensions::ExtensionKeybindingRegistry::PLATFORM_APPS_ONLY,
714 NULL)); 750 NULL));
715 } 751 }
752
753 // ExclusiveAccessContext implementation
754
755 Profile* ChromeNativeAppWindowViews::GetProfile() {
756 return Profile::FromBrowserContext(app_window()->browser_context());
757 }
758
759 bool ChromeNativeAppWindowViews::IsFullscreen() const {
760 return NativeAppWindowViews::IsFullscreen();
761 }
762
763 bool ChromeNativeAppWindowViews::IsFullscreenWithToolbar() {
764 return false;
765 }
766
767 bool ChromeNativeAppWindowViews::SupportsFullscreenWithToolbar() {
768 return false;
769 }
770
771 void ChromeNativeAppWindowViews::EnterFullscreen(
772 const GURL& url,
773 ExclusiveAccessBubbleType bubble_type,
774 bool with_toolbar) {
775 app_window()->Fullscreen();
776 UpdateExclusiveAccessExitBubbleContent(url, bubble_type);
777 }
778
779 void ChromeNativeAppWindowViews::ExitFullscreen() {
780 app_window()->Restore();
781 UpdateExclusiveAccessExitBubbleContent(GURL(),
782 EXCLUSIVE_ACCESS_BUBBLE_TYPE_NONE);
783 }
784
785 void ChromeNativeAppWindowViews::UpdateExclusiveAccessExitBubbleContent(
786 GURL url,
787 ExclusiveAccessBubbleType bubble_type) {
788 if (bubble_type == EXCLUSIVE_ACCESS_BUBBLE_TYPE_NONE || url.is_empty()) {
789 exclusive_access_bubble_views_.reset();
790 } else if (exclusive_access_bubble_views_.get()) {
791 exclusive_access_bubble_views_->UpdateContent(url, bubble_type);
792 } else {
793 exclusive_access_bubble_views_.reset(
794 new ExclusiveAccessBubbleViews(this, url, bubble_type));
795 }
796 }
797
798 content::WebContents* ChromeNativeAppWindowViews::GetActiveWebContents() {
799 return web_view()->GetWebContents();
800 }
801
802 void ChromeNativeAppWindowViews::UpdateFullscreenWithToolbar(
803 bool with_toolbar) {
804 // This is currently a Mac only feature.
805 NOTIMPLEMENTED();
806 }
807
808 void ChromeNativeAppWindowViews::SetMetroSnapMode(bool enable) {
809 // Not implemented for chrome app.
810 NOTIMPLEMENTED();
811 }
812
813 bool ChromeNativeAppWindowViews::IsInMetroSnapMode() {
814 return false;
815 }
816
817 void ChromeNativeAppWindowViews::UpdateDownloadShelf(bool unhide) {
818 // Apps don't have a download shelf and so nothing to do here.
819 }
820
821 bool ChromeNativeAppWindowViews::UseCallbackForMouseLock() {
822 return true;
823 }
824
825 bool ChromeNativeAppWindowViews::MouseLockCallback(bool acquired) {
826 if (key_capture_requested_ && acquired) {
827 desktop_keyboard_capture_.reset(new DesktopKeyboardCapture(widget()));
828 } else {
829 desktop_keyboard_capture_.reset(nullptr);
830 }
831
832 return key_capture_requested_;
833 }
834
835 // ExclusiveAccessBubbleViewsContext implementation
836 ExclusiveAccessManager*
837 ChromeNativeAppWindowViews::GetExclusiveAccessManager() {
838 return exclusive_access_manager_.get();
839 }
840
841 views::Widget* ChromeNativeAppWindowViews::GetWidget() {
842 return widget();
843 }
844
845 bool ChromeNativeAppWindowViews::IsImmersiveModeEnabled() {
846 return false;
847 }
848
849 gfx::Rect ChromeNativeAppWindowViews::GetTopContainerBoundsInScreen() {
850 return widget()->GetWindowBoundsInScreen();
851 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/apps/chrome_native_app_window_views.h ('k') | extensions/browser/app_window/native_app_window.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698