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/frame/immersive_mode_controller_ash.cc

Issue 27458002: Allow setting different hit test bounds overrides for mouse and touch (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 2 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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/frame/immersive_mode_controller_ash.h" 5 #include "chrome/browser/ui/views/frame/immersive_mode_controller_ash.h"
6 6
7 #include <set> 7 #include <set>
8 #include <vector> 8 #include <vector>
9 9
10 #include "ash/ash_switches.h" 10 #include "ash/ash_switches.h"
11 #include "ash/shell.h" 11 #include "ash/shell.h"
12 #include "ash/wm/window_properties.h" 12 #include "ash/wm/window_properties.h"
13 #include "base/command_line.h" 13 #include "ash/wm/wm_types.h"
14 #include "chrome/browser/chrome_notification_types.h" 14 #include "chrome/browser/chrome_notification_types.h"
15 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h" 15 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h"
16 #include "chrome/browser/ui/immersive_fullscreen_configuration.h" 16 #include "chrome/browser/ui/immersive_fullscreen_configuration.h"
17 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h" 17 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h"
18 #include "chrome/browser/ui/views/frame/top_container_view.h" 18 #include "chrome/browser/ui/views/frame/top_container_view.h"
19 #include "content/public/browser/notification_service.h" 19 #include "content/public/browser/notification_service.h"
20 #include "content/public/browser/web_contents.h"
21 #include "content/public/browser/web_contents_view.h"
22 #include "ui/aura/client/activation_client.h" 20 #include "ui/aura/client/activation_client.h"
23 #include "ui/aura/client/aura_constants.h" 21 #include "ui/aura/client/aura_constants.h"
24 #include "ui/aura/client/capture_client.h" 22 #include "ui/aura/client/capture_client.h"
25 #include "ui/aura/client/cursor_client.h" 23 #include "ui/aura/client/cursor_client.h"
26 #include "ui/aura/client/screen_position_client.h" 24 #include "ui/aura/client/screen_position_client.h"
27 #include "ui/aura/env.h" 25 #include "ui/aura/env.h"
28 #include "ui/aura/root_window.h" 26 #include "ui/aura/root_window.h"
29 #include "ui/aura/window.h" 27 #include "ui/aura/window.h"
30 #include "ui/gfx/animation/slide_animation.h" 28 #include "ui/gfx/animation/slide_animation.h"
31 #include "ui/views/bubble/bubble_delegate.h" 29 #include "ui/views/bubble/bubble_delegate.h"
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 //////////////////////////////////////////////////////////////////////////////// 258 ////////////////////////////////////////////////////////////////////////////////
261 259
262 ImmersiveModeControllerAsh::ImmersiveModeControllerAsh() 260 ImmersiveModeControllerAsh::ImmersiveModeControllerAsh()
263 : delegate_(NULL), 261 : delegate_(NULL),
264 widget_(NULL), 262 widget_(NULL),
265 top_container_(NULL), 263 top_container_(NULL),
266 observers_enabled_(false), 264 observers_enabled_(false),
267 enabled_(false), 265 enabled_(false),
268 reveal_state_(CLOSED), 266 reveal_state_(CLOSED),
269 revealed_lock_count_(0), 267 revealed_lock_count_(0),
270 tab_indicator_visibility_(TAB_INDICATORS_HIDE),
271 mouse_x_when_hit_top_in_screen_(-1), 268 mouse_x_when_hit_top_in_screen_(-1),
272 gesture_begun_(false), 269 gesture_begun_(false),
273 native_window_(NULL), 270 native_window_(NULL),
274 animation_(new gfx::SlideAnimation(this)), 271 animation_(new gfx::SlideAnimation(this)),
275 animations_disabled_for_test_(false), 272 animations_disabled_for_test_(false),
276 weak_ptr_factory_(this) { 273 weak_ptr_factory_(this) {
277 } 274 }
278 275
279 ImmersiveModeControllerAsh::~ImmersiveModeControllerAsh() { 276 ImmersiveModeControllerAsh::~ImmersiveModeControllerAsh() {
280 // The browser view is being destroyed so there's no need to update its 277 // The browser view is being destroyed so there's no need to update its
(...skipping 27 matching lines...) Expand all
308 void ImmersiveModeControllerAsh::Init( 305 void ImmersiveModeControllerAsh::Init(
309 Delegate* delegate, 306 Delegate* delegate,
310 views::Widget* widget, 307 views::Widget* widget,
311 views::View* top_container) { 308 views::View* top_container) {
312 delegate_ = delegate; 309 delegate_ = delegate;
313 widget_ = widget; 310 widget_ = widget;
314 // Browser view is detached from its widget during destruction. Cache the 311 // Browser view is detached from its widget during destruction. Cache the
315 // window pointer so |this| can stop observing during destruction. 312 // window pointer so |this| can stop observing during destruction.
316 native_window_ = widget_->GetNativeWindow(); 313 native_window_ = widget_->GetNativeWindow();
317 top_container_ = top_container; 314 top_container_ = top_container;
318
319 // Optionally allow the tab indicators to be hidden.
320 if (CommandLine::ForCurrentProcess()->
321 HasSwitch(ash::switches::kAshImmersiveHideTabIndicators)) {
322 tab_indicator_visibility_ = TAB_INDICATORS_FORCE_HIDE;
323 }
324 } 315 }
325 316
326 void ImmersiveModeControllerAsh::SetEnabled(bool enabled) { 317 void ImmersiveModeControllerAsh::SetEnabled(bool enabled) {
327 DCHECK(native_window_) << "Must initialize before enabling"; 318 DCHECK(native_window_) << "Must initialize before enabling";
328 if (enabled_ == enabled) 319 if (enabled_ == enabled)
329 return; 320 return;
330 enabled_ = enabled; 321 enabled_ = enabled;
331 322
332 EnableWindowObservers(enabled_); 323 EnableWindowObservers(enabled_);
333 324
(...skipping 22 matching lines...) Expand all
356 UpdateLocatedEventRevealedLock(NULL, ALLOW_REVEAL_WHILE_CLOSING_NO); 347 UpdateLocatedEventRevealedLock(NULL, ALLOW_REVEAL_WHILE_CLOSING_NO);
357 UpdateFocusRevealedLock(); 348 UpdateFocusRevealedLock();
358 } 349 }
359 } else { 350 } else {
360 // Stop cursor-at-top tracking. 351 // Stop cursor-at-top tracking.
361 top_edge_hover_timer_.Stop(); 352 top_edge_hover_timer_.Stop();
362 // Snap immediately to the closed state. 353 // Snap immediately to the closed state.
363 reveal_state_ = CLOSED; 354 reveal_state_ = CLOSED;
364 EnablePaintToLayer(false); 355 EnablePaintToLayer(false);
365 delegate_->SetImmersiveStyle(false); 356 delegate_->SetImmersiveStyle(false);
366 SetRenderWindowTopInsetsForTouch(0);
367 357
368 // Layout the root view so that incognito avatar icon, if any, gets laid 358 // Layout the root view so that incognito avatar icon, if any, gets laid
369 // out. 359 // out.
370 LayoutBrowserRootView(); 360 LayoutBrowserRootView();
371 } 361 }
372 } 362 }
373 363
374 bool ImmersiveModeControllerAsh::IsEnabled() const { 364 bool ImmersiveModeControllerAsh::IsEnabled() const {
375 return enabled_; 365 return enabled_;
376 } 366 }
377 367
378 bool ImmersiveModeControllerAsh::ShouldHideTabIndicators() const { 368 bool ImmersiveModeControllerAsh::ShouldHideTabIndicators() const {
379 return tab_indicator_visibility_ != TAB_INDICATORS_SHOW; 369 return native_window_->GetProperty(ash::internal::kFullscreenTypeKey) !=
370 ash::wm::FULLSCREEN_TYPE_IMMERSIVE_MINIMAL_CHROME;
380 } 371 }
381 372
382 bool ImmersiveModeControllerAsh::ShouldHideTopViews() const { 373 bool ImmersiveModeControllerAsh::ShouldHideTopViews() const {
383 return enabled_ && reveal_state_ == CLOSED; 374 return enabled_ && reveal_state_ == CLOSED;
384 } 375 }
385 376
386 bool ImmersiveModeControllerAsh::IsRevealed() const { 377 bool ImmersiveModeControllerAsh::IsRevealed() const {
387 return enabled_ && reveal_state_ != CLOSED; 378 return enabled_ && reveal_state_ != CLOSED;
388 } 379 }
389 380
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 588
598 void ImmersiveModeControllerAsh::OnRemoveTransientChild( 589 void ImmersiveModeControllerAsh::OnRemoveTransientChild(
599 aura::Window* window, 590 aura::Window* window,
600 aura::Window* transient) { 591 aura::Window* transient) {
601 bubble_manager_->StopObserving(transient); 592 bubble_manager_->StopObserving(transient);
602 } 593 }
603 594
604 //////////////////////////////////////////////////////////////////////////////// 595 ////////////////////////////////////////////////////////////////////////////////
605 // Testing interface: 596 // Testing interface:
606 597
607 void ImmersiveModeControllerAsh::SetForceHideTabIndicatorsForTest(bool force) {
608 if (force)
609 tab_indicator_visibility_ = TAB_INDICATORS_FORCE_HIDE;
610 else if (tab_indicator_visibility_ == TAB_INDICATORS_FORCE_HIDE)
611 tab_indicator_visibility_ = TAB_INDICATORS_HIDE;
612 UpdateUseMinimalChrome(LAYOUT_YES);
613 }
614
615 void ImmersiveModeControllerAsh::StartRevealForTest(bool hovered) { 598 void ImmersiveModeControllerAsh::StartRevealForTest(bool hovered) {
616 MaybeStartReveal(ANIMATE_NO); 599 MaybeStartReveal(ANIMATE_NO);
617 MoveMouse(top_container_, hovered); 600 MoveMouse(top_container_, hovered);
618 UpdateLocatedEventRevealedLock(NULL, ALLOW_REVEAL_WHILE_CLOSING_NO); 601 UpdateLocatedEventRevealedLock(NULL, ALLOW_REVEAL_WHILE_CLOSING_NO);
619 } 602 }
620 603
621 void ImmersiveModeControllerAsh::SetMouseHoveredForTest(bool hovered) { 604 void ImmersiveModeControllerAsh::SetMouseHoveredForTest(bool hovered) {
622 MoveMouse(top_container_, hovered); 605 MoveMouse(top_container_, hovered);
623 UpdateLocatedEventRevealedLock(NULL, ALLOW_REVEAL_WHILE_CLOSING_NO); 606 UpdateLocatedEventRevealedLock(NULL, ALLOW_REVEAL_WHILE_CLOSING_NO);
624 } 607 }
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
895 878
896 // Ending the reveal was unsuccessful. Reaquire the locks if appropriate. 879 // Ending the reveal was unsuccessful. Reaquire the locks if appropriate.
897 UpdateLocatedEventRevealedLock(NULL, ALLOW_REVEAL_WHILE_CLOSING_NO); 880 UpdateLocatedEventRevealedLock(NULL, ALLOW_REVEAL_WHILE_CLOSING_NO);
898 UpdateFocusRevealedLock(); 881 UpdateFocusRevealedLock();
899 } 882 }
900 } 883 }
901 return false; 884 return false;
902 } 885 }
903 886
904 void ImmersiveModeControllerAsh::UpdateUseMinimalChrome(Layout layout) { 887 void ImmersiveModeControllerAsh::UpdateUseMinimalChrome(Layout layout) {
905 // May be NULL in tests. 888 ash::wm::FullscreenType previous_fullscreen_type =
906 FullscreenController* fullscreen_controller = 889 native_window_->GetProperty(ash::internal::kFullscreenTypeKey);
907 delegate_->GetFullscreenController();
908 bool in_tab_fullscreen = fullscreen_controller ?
909 fullscreen_controller->IsFullscreenForTabOrPending() : false;
910 bool use_minimal_chrome = !in_tab_fullscreen && enabled_;
911 native_window_->SetProperty(ash::internal::kFullscreenUsesMinimalChromeKey,
912 use_minimal_chrome);
913 890
914 TabIndicatorVisibility previous_tab_indicator_visibility = 891 ash::wm::FullscreenType fullscreen_type = ash::wm::FULLSCREEN_TYPE_OTHER;
915 tab_indicator_visibility_; 892 if (enabled_) {
916 if (tab_indicator_visibility_ != TAB_INDICATORS_FORCE_HIDE) { 893 // May be NULL in tests.
917 tab_indicator_visibility_ = use_minimal_chrome ? 894 FullscreenController* fullscreen_controller =
918 TAB_INDICATORS_SHOW : TAB_INDICATORS_HIDE; 895 delegate_->GetFullscreenController();
896 bool in_tab_fullscreen = fullscreen_controller ?
897 fullscreen_controller->IsFullscreenForTabOrPending() : false;
898 fullscreen_type = in_tab_fullscreen ?
899 ash::wm::FULLSCREEN_TYPE_IMMERSIVE_NO_CHROME :
900 ash::wm::FULLSCREEN_TYPE_IMMERSIVE_MINIMAL_CHROME;
919 } 901 }
920 902
903 if (fullscreen_type == previous_fullscreen_type)
904 return;
905 native_window_->SetProperty(ash::internal::kFullscreenTypeKey,
906 fullscreen_type);
907
921 // Ash on Windows may not have a shell. 908 // Ash on Windows may not have a shell.
922 if (ash::Shell::HasInstance()) { 909 if (ash::Shell::HasInstance()) {
923 // When using minimal chrome, the shelf is auto-hidden. The auto-hidden 910 // When using minimal chrome, the shelf is auto-hidden. The auto-hidden
924 // shelf displays a 3px 'light bar' when it is closed. 911 // shelf displays a 3px 'light bar' when it is closed.
925 ash::Shell::GetInstance()->UpdateShelfVisibility(); 912 ash::Shell::GetInstance()->UpdateShelfVisibility();
926 } 913 }
927 914
928 if (tab_indicator_visibility_ != previous_tab_indicator_visibility) { 915 // If the top-of-window views are revealed or animating, the change will
929 // If the top-of-window views are revealed or animating, the change will 916 // take effect with the layout once the top-of-window views are closed.
930 // take effect with the layout once the top-of-window views are closed. 917 if (layout == LAYOUT_YES && reveal_state_ == CLOSED)
931 if (layout == LAYOUT_YES && reveal_state_ == CLOSED) 918 LayoutBrowserRootView();
932 LayoutBrowserRootView();
933 }
934 } 919 }
935 920
936 int ImmersiveModeControllerAsh::GetAnimationDuration(Animate animate) const { 921 int ImmersiveModeControllerAsh::GetAnimationDuration(Animate animate) const {
937 switch (animate) { 922 switch (animate) {
938 case ANIMATE_NO: 923 case ANIMATE_NO:
939 return 0; 924 return 0;
940 case ANIMATE_SLOW: 925 case ANIMATE_SLOW:
941 return kRevealSlowAnimationDurationMs; 926 return kRevealSlowAnimationDurationMs;
942 case ANIMATE_FAST: 927 case ANIMATE_FAST:
943 return kRevealFastAnimationDurationMs; 928 return kRevealFastAnimationDurationMs;
(...skipping 20 matching lines...) Expand all
964 reveal_state_ = SLIDING_OPEN; 949 reveal_state_ = SLIDING_OPEN;
965 if (previous_reveal_state == CLOSED) { 950 if (previous_reveal_state == CLOSED) {
966 // Turn on layer painting so that we can overlap the web contents. 951 // Turn on layer painting so that we can overlap the web contents.
967 EnablePaintToLayer(true); 952 EnablePaintToLayer(true);
968 953
969 // Ensure window caption buttons are updated and the view bounds are 954 // Ensure window caption buttons are updated and the view bounds are
970 // computed at normal (non-immersive-style) size. The layout call moves the 955 // computed at normal (non-immersive-style) size. The layout call moves the
971 // top-of-window views to their initial offscreen position for the 956 // top-of-window views to their initial offscreen position for the
972 // animation. 957 // animation.
973 delegate_->SetImmersiveStyle(false); 958 delegate_->SetImmersiveStyle(false);
974 SetRenderWindowTopInsetsForTouch(0);
975 LayoutBrowserRootView(); 959 LayoutBrowserRootView();
976 960
977 // Do not do any more processing if LayoutBrowserView() changed 961 // Do not do any more processing if LayoutBrowserView() changed
978 // |reveal_state_|. 962 // |reveal_state_|.
979 if (reveal_state_ != SLIDING_OPEN) { 963 if (reveal_state_ != SLIDING_OPEN) {
980 if (reveal_state_ == REVEALED) 964 if (reveal_state_ == REVEALED)
981 FOR_EACH_OBSERVER(Observer, observers_, OnImmersiveRevealStarted()); 965 FOR_EACH_OBSERVER(Observer, observers_, OnImmersiveRevealStarted());
982 return; 966 return;
983 } 967 }
984 } 968 }
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
1062 } 1046 }
1063 } 1047 }
1064 1048
1065 void ImmersiveModeControllerAsh::OnSlideClosedAnimationCompleted() { 1049 void ImmersiveModeControllerAsh::OnSlideClosedAnimationCompleted() {
1066 DCHECK_EQ(SLIDING_CLOSED, reveal_state_); 1050 DCHECK_EQ(SLIDING_CLOSED, reveal_state_);
1067 reveal_state_ = CLOSED; 1051 reveal_state_ = CLOSED;
1068 // Layers aren't needed after animation completes. 1052 // Layers aren't needed after animation completes.
1069 EnablePaintToLayer(false); 1053 EnablePaintToLayer(false);
1070 // Update tabstrip for closed state. 1054 // Update tabstrip for closed state.
1071 delegate_->SetImmersiveStyle(true); 1055 delegate_->SetImmersiveStyle(true);
1072 SetRenderWindowTopInsetsForTouch(kNearTopContainerDistance);
1073 LayoutBrowserRootView(); 1056 LayoutBrowserRootView();
1074 } 1057 }
1075 1058
1076 bool ImmersiveModeControllerAsh::ShouldExitImmersiveFullscreen() const { 1059 bool ImmersiveModeControllerAsh::ShouldExitImmersiveFullscreen() const {
1077 if (!native_window_) 1060 if (!native_window_)
1078 return false; 1061 return false;
1079 1062
1080 ui::WindowShowState show_state = static_cast<ui::WindowShowState>( 1063 ui::WindowShowState show_state = static_cast<ui::WindowShowState>(
1081 native_window_->GetProperty(aura::client::kShowStateKey)); 1064 native_window_->GetProperty(aura::client::kShowStateKey));
1082 return IsEnabled() && 1065 return IsEnabled() &&
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1142 // the closest screen ensures that the event is from a valid bezel and can be 1125 // the closest screen ensures that the event is from a valid bezel and can be
1143 // interpreted as such. 1126 // interpreted as such.
1144 gfx::Rect screen_bounds = 1127 gfx::Rect screen_bounds =
1145 ash::Shell::GetScreen()->GetDisplayNearestPoint(location).bounds(); 1128 ash::Shell::GetScreen()->GetDisplayNearestPoint(location).bounds();
1146 return (!screen_bounds.Contains(location) && 1129 return (!screen_bounds.Contains(location) &&
1147 location.y() < top_container_bounds_in_screen.y() && 1130 location.y() < top_container_bounds_in_screen.y() &&
1148 location.x() >= top_container_bounds_in_screen.x() && 1131 location.x() >= top_container_bounds_in_screen.x() &&
1149 location.x() < top_container_bounds_in_screen.right()); 1132 location.x() < top_container_bounds_in_screen.right());
1150 } 1133 }
1151 1134
1152 void ImmersiveModeControllerAsh::SetRenderWindowTopInsetsForTouch(
1153 int top_inset) {
1154 content::WebContents* contents = delegate_->GetWebContents();
1155 if (contents) {
1156 aura::Window* window = contents->GetView()->GetContentNativeView();
1157 // |window| is NULL if the renderer crashed.
1158 if (window) {
1159 gfx::Insets inset(top_inset, 0, 0, 0);
1160 window->SetHitTestBoundsOverrideOuter(
1161 window->hit_test_bounds_override_outer_mouse(),
1162 inset);
1163 }
1164 }
1165 }
1166
1167 void ImmersiveModeControllerAsh::RecreateBubbleManager() { 1135 void ImmersiveModeControllerAsh::RecreateBubbleManager() {
1168 bubble_manager_.reset(new BubbleManager(this)); 1136 bubble_manager_.reset(new BubbleManager(this));
1169 const std::vector<aura::Window*> transient_children = 1137 const std::vector<aura::Window*> transient_children =
1170 native_window_->transient_children(); 1138 native_window_->transient_children();
1171 for (size_t i = 0; i < transient_children.size(); ++i) { 1139 for (size_t i = 0; i < transient_children.size(); ++i) {
1172 aura::Window* transient_child = transient_children[i]; 1140 aura::Window* transient_child = transient_children[i];
1173 views::BubbleDelegateView* bubble_delegate = 1141 views::BubbleDelegateView* bubble_delegate =
1174 AsBubbleDelegate(transient_child); 1142 AsBubbleDelegate(transient_child);
1175 if (bubble_delegate && 1143 if (bubble_delegate &&
1176 bubble_delegate->GetAnchorView() && 1144 bubble_delegate->GetAnchorView() &&
1177 top_container_->Contains(bubble_delegate->GetAnchorView())) { 1145 top_container_->Contains(bubble_delegate->GetAnchorView())) {
1178 bubble_manager_->StartObserving(transient_child); 1146 bubble_manager_->StartObserving(transient_child);
1179 } 1147 }
1180 } 1148 }
1181 } 1149 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698