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

Side by Side Diff: chrome/browser/ui/views/frame/immersive_mode_controller_ash.cc

Issue 15734011: Correct immersive mode gestures under rotation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Moved SetPreTargetHandler() to private section Created 7 years, 7 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 "ash/ash_switches.h" 7 #include "ash/ash_switches.h"
8 #include "ash/shell.h" 8 #include "ash/shell.h"
9 #include "ash/wm/window_properties.h" 9 #include "ash/wm/window_properties.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h" 11 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h"
12 #include "chrome/browser/ui/immersive_fullscreen_configuration.h" 12 #include "chrome/browser/ui/immersive_fullscreen_configuration.h"
13 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h" 13 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h"
14 #include "chrome/browser/ui/views/frame/top_container_view.h" 14 #include "chrome/browser/ui/views/frame/top_container_view.h"
15 #include "chrome/common/chrome_notification_types.h" 15 #include "chrome/common/chrome_notification_types.h"
16 #include "content/public/browser/notification_service.h" 16 #include "content/public/browser/notification_service.h"
17 #include "ui/aura/client/activation_client.h" 17 #include "ui/aura/client/activation_client.h"
18 #include "ui/aura/client/aura_constants.h" 18 #include "ui/aura/client/aura_constants.h"
19 #include "ui/aura/client/capture_client.h" 19 #include "ui/aura/client/capture_client.h"
20 #include "ui/aura/env.h" 20 #include "ui/aura/env.h"
21 #include "ui/aura/root_window.h"
21 #include "ui/aura/window.h" 22 #include "ui/aura/window.h"
22 #include "ui/aura/window_observer.h"
23 #include "ui/compositor/layer_animation_observer.h" 23 #include "ui/compositor/layer_animation_observer.h"
24 #include "ui/compositor/scoped_layer_animation_settings.h" 24 #include "ui/compositor/scoped_layer_animation_settings.h"
25 #include "ui/gfx/screen.h" 25 #include "ui/gfx/screen.h"
26 #include "ui/gfx/transform.h" 26 #include "ui/gfx/transform.h"
27 #include "ui/views/view.h" 27 #include "ui/views/view.h"
28 #include "ui/views/widget/widget.h" 28 #include "ui/views/widget/widget.h"
29 #include "ui/views/window/non_client_view.h" 29 #include "ui/views/window/non_client_view.h"
30 30
31 using views::View; 31 using views::View;
32 32
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 288
289 UpdateRevealedLock(); 289 UpdateRevealedLock();
290 290
291 std::map<views::Widget*, int>::iterator it = widgets_.find(widget); 291 std::map<views::Widget*, int>::iterator it = widgets_.find(widget);
292 DCHECK(it != widgets_.end()); 292 DCHECK(it != widgets_.end());
293 UpdateWidgetBounds(it->first, it->second); 293 UpdateWidgetBounds(it->first, it->second);
294 } 294 }
295 295
296 //////////////////////////////////////////////////////////////////////////////// 296 ////////////////////////////////////////////////////////////////////////////////
297 297
298 // Observer to watch for window restore. views::Widget does not provide a hook
299 // to observe for window restore, so do this at the Aura level.
300 class ImmersiveModeControllerAsh::WindowObserver : public aura::WindowObserver {
301 public:
302 explicit WindowObserver(ImmersiveModeControllerAsh* controller)
303 : controller_(controller) {
304 controller_->native_window_->AddObserver(this);
305 }
306
307 virtual ~WindowObserver() {
308 controller_->native_window_->RemoveObserver(this);
309 }
310
311 // aura::WindowObserver overrides:
312 virtual void OnWindowPropertyChanged(aura::Window* window,
313 const void* key,
314 intptr_t old) OVERRIDE {
315 using aura::client::kShowStateKey;
316 if (key == kShowStateKey) {
317 // Disable immersive mode when leaving the fullscreen state.
318 ui::WindowShowState show_state = static_cast<ui::WindowShowState>(
319 window->GetProperty(kShowStateKey));
320 if (controller_->IsEnabled() &&
321 show_state != ui::SHOW_STATE_FULLSCREEN &&
322 show_state != ui::SHOW_STATE_MINIMIZED) {
323 controller_->delegate_->FullscreenStateChanged();
324 }
325 return;
326 }
327 }
328
329 private:
330 ImmersiveModeControllerAsh* controller_; // Not owned.
331
332 DISALLOW_COPY_AND_ASSIGN(WindowObserver);
333 };
334
335 ////////////////////////////////////////////////////////////////////////////////
336
337 ImmersiveModeControllerAsh::ImmersiveModeControllerAsh() 298 ImmersiveModeControllerAsh::ImmersiveModeControllerAsh()
338 : delegate_(NULL), 299 : delegate_(NULL),
339 widget_(NULL), 300 widget_(NULL),
340 top_container_(NULL), 301 top_container_(NULL),
341 observers_enabled_(false), 302 observers_enabled_(false),
342 enabled_(false), 303 enabled_(false),
343 reveal_state_(CLOSED), 304 reveal_state_(CLOSED),
344 revealed_lock_count_(0), 305 revealed_lock_count_(0),
345 tab_indicator_visibility_(TAB_INDICATORS_HIDE), 306 tab_indicator_visibility_(TAB_INDICATORS_HIDE),
346 mouse_x_when_hit_top_(-1), 307 mouse_x_when_hit_top_(-1),
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 if (!enabled_) 497 if (!enabled_)
537 return; 498 return;
538 499
539 // Touch gestures should not initiate revealing the top-of-window views while 500 // Touch gestures should not initiate revealing the top-of-window views while
540 // |native_window_| is inactive. 501 // |native_window_| is inactive.
541 if (!views::Widget::GetWidgetForNativeWindow(native_window_)->IsActive()) 502 if (!views::Widget::GetWidgetForNativeWindow(native_window_)->IsActive())
542 return; 503 return;
543 504
544 switch (event->type()) { 505 switch (event->type()) {
545 case ui::ET_GESTURE_SCROLL_BEGIN: 506 case ui::ET_GESTURE_SCROLL_BEGIN:
546 if (IsNearTopContainer(event->location())) { 507 if (ShouldHandleEvent(event->location())) {
547 gesture_begun_ = true; 508 gesture_begun_ = true;
548 event->SetHandled(); 509 event->SetHandled();
549 } 510 }
550 break; 511 break;
551 case ui::ET_GESTURE_SCROLL_UPDATE: 512 case ui::ET_GESTURE_SCROLL_UPDATE:
552 if (gesture_begun_) { 513 if (gesture_begun_) {
553 SwipeType swipe_type = GetSwipeType(event); 514 SwipeType swipe_type = GetSwipeType(event);
554 if ((reveal_state_ == SLIDING_CLOSED || reveal_state_ == CLOSED) && 515 if ((reveal_state_ == SLIDING_CLOSED || reveal_state_ == CLOSED) &&
555 swipe_type == SWIPE_OPEN) { 516 swipe_type == SWIPE_OPEN) {
556 delegate_->FocusLocationBar(); 517 delegate_->FocusLocationBar();
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 // Animation observer: 570 // Animation observer:
610 571
611 void ImmersiveModeControllerAsh::OnImplicitAnimationsCompleted() { 572 void ImmersiveModeControllerAsh::OnImplicitAnimationsCompleted() {
612 if (reveal_state_ == SLIDING_OPEN) 573 if (reveal_state_ == SLIDING_OPEN)
613 OnSlideOpenAnimationCompleted(); 574 OnSlideOpenAnimationCompleted();
614 else if (reveal_state_ == SLIDING_CLOSED) 575 else if (reveal_state_ == SLIDING_CLOSED)
615 OnSlideClosedAnimationCompleted(); 576 OnSlideClosedAnimationCompleted();
616 } 577 }
617 578
618 //////////////////////////////////////////////////////////////////////////////// 579 ////////////////////////////////////////////////////////////////////////////////
580 // aura::WindowObserver overrides:
581 void ImmersiveModeControllerAsh::OnWindowPropertyChanged(aura::Window* window,
582 const void* key,
583 intptr_t old) {
584 using aura::client::kShowStateKey;
585 if (key == kShowStateKey) {
586 // Disable immersive mode when leaving the fullscreen state.
587 ui::WindowShowState show_state = static_cast<ui::WindowShowState>(
588 window->GetProperty(kShowStateKey));
589 if (IsEnabled() &&
590 show_state != ui::SHOW_STATE_FULLSCREEN &&
591 show_state != ui::SHOW_STATE_MINIMIZED) {
592 delegate_->FullscreenStateChanged();
593 }
594 }
595 }
596
597 void ImmersiveModeControllerAsh::OnWindowAddedToRootWindow(
598 aura::Window* window) {
599 DCHECK_EQ(window, native_window_);
600 SetPreTargetHandler();
601 }
602
603 void ImmersiveModeControllerAsh::OnWindowRemovedFromRootWindow(
604 aura::Window* window) {
605 DCHECK_EQ(window, native_window_);
606 SetPreTargetHandler();
607 }
608
609 ////////////////////////////////////////////////////////////////////////////////
619 // Testing interface: 610 // Testing interface:
620 611
621 void ImmersiveModeControllerAsh::SetForceHideTabIndicatorsForTest(bool force) { 612 void ImmersiveModeControllerAsh::SetForceHideTabIndicatorsForTest(bool force) {
622 if (force) 613 if (force)
623 tab_indicator_visibility_ = TAB_INDICATORS_FORCE_HIDE; 614 tab_indicator_visibility_ = TAB_INDICATORS_FORCE_HIDE;
624 else if (tab_indicator_visibility_ == TAB_INDICATORS_FORCE_HIDE) 615 else if (tab_indicator_visibility_ == TAB_INDICATORS_FORCE_HIDE)
625 tab_indicator_visibility_ = TAB_INDICATORS_HIDE; 616 tab_indicator_visibility_ = TAB_INDICATORS_HIDE;
626 UpdateUseMinimalChrome(LAYOUT_YES); 617 UpdateUseMinimalChrome(LAYOUT_YES);
627 } 618 }
628 619
(...skipping 25 matching lines...) Expand all
654 views::Widget::GetWidgetForNativeWindow(native_window_); 645 views::Widget::GetWidgetForNativeWindow(native_window_);
655 views::FocusManager* focus_manager = widget->GetFocusManager(); 646 views::FocusManager* focus_manager = widget->GetFocusManager();
656 if (enable) { 647 if (enable) {
657 widget->AddObserver(this); 648 widget->AddObserver(this);
658 focus_manager->AddFocusChangeListener(this); 649 focus_manager->AddFocusChangeListener(this);
659 } else { 650 } else {
660 widget->RemoveObserver(this); 651 widget->RemoveObserver(this);
661 focus_manager->RemoveFocusChangeListener(this); 652 focus_manager->RemoveFocusChangeListener(this);
662 } 653 }
663 654
664 if (enable) 655 SetPreTargetHandler();
665 native_window_->AddPreTargetHandler(this);
666 else
667 native_window_->RemovePreTargetHandler(this);
668 656
669 // The window observer adds and removes itself from the native window. 657 if (enable) {
670 window_observer_.reset(enable ? new WindowObserver(this) : NULL); 658 native_window_->AddObserver(this);
659 } else {
660 native_window_->RemoveObserver(this);
661 }
671 662
672 if (enable) { 663 if (enable) {
673 registrar_.Add( 664 registrar_.Add(
674 this, 665 this,
675 chrome::NOTIFICATION_FULLSCREEN_CHANGED, 666 chrome::NOTIFICATION_FULLSCREEN_CHANGED,
676 content::Source<FullscreenController>( 667 content::Source<FullscreenController>(
677 delegate_->GetFullscreenController())); 668 delegate_->GetFullscreenController()));
678 } else { 669 } else {
679 registrar_.Remove( 670 registrar_.Remove(
680 this, 671 this,
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
1020 if (abs(event->details().scroll_y()) <= 1011 if (abs(event->details().scroll_y()) <=
1021 kSwipeVerticalThresholdMultiplier * abs(event->details().scroll_x())) 1012 kSwipeVerticalThresholdMultiplier * abs(event->details().scroll_x()))
1022 return SWIPE_NONE; 1013 return SWIPE_NONE;
1023 if (event->details().scroll_y() < 0) 1014 if (event->details().scroll_y() < 0)
1024 return SWIPE_CLOSE; 1015 return SWIPE_CLOSE;
1025 else if (event->details().scroll_y() > 0) 1016 else if (event->details().scroll_y() > 0)
1026 return SWIPE_OPEN; 1017 return SWIPE_OPEN;
1027 return SWIPE_NONE; 1018 return SWIPE_NONE;
1028 } 1019 }
1029 1020
1030 bool ImmersiveModeControllerAsh::IsNearTopContainer(gfx::Point location) const { 1021 bool ImmersiveModeControllerAsh::ShouldHandleEvent(
1022 const gfx::Point& location) const {
1023 // All of the gestures that are of interest start in a region with left &
1024 // right edges agreeing with |top_container_|. When CLOSED it is difficult to
1025 // hit the bounds due to small on screen size, so the hit target needs to be
pkotwicz 2013/05/27 21:32:46 The small size of the tab strip?
rharrison 2013/05/28 17:03:01 Done.
1026 // extended on the bottom, thus the inset call. Finally there may be a bezel
1027 // sensor off screen logically above |top_container_| thus the test needs to
1028 // include gestures starting above.
1031 gfx::Rect near_bounds = top_container_->GetTargetBoundsInScreen(); 1029 gfx::Rect near_bounds = top_container_->GetTargetBoundsInScreen();
1032 if (reveal_state_ == CLOSED) 1030 if (reveal_state_ == CLOSED)
1033 near_bounds.Inset(gfx::Insets(0, 0, -kNearTopContainerDistance, 0)); 1031 near_bounds.Inset(gfx::Insets(0, 0, -kNearTopContainerDistance, 0));
1034 return near_bounds.Contains(location); 1032 return near_bounds.Contains(location) ||
1033 ((location.y() < near_bounds.y()) &&
1034 (location.x() >= near_bounds.x()) &&
1035 (location.x() <= near_bounds.x() + near_bounds.right()));
pkotwicz 2013/05/27 21:32:46 This is supposed to be near_bounds.right() instead
rharrison 2013/05/28 17:03:01 Done.
1035 } 1036 }
1037
1038 void ImmersiveModeControllerAsh::SetPreTargetHandler() {
1039 if (!native_window_)
1040 return;
1041 aura::RootWindow* root_window = native_window_->GetRootWindow();
1042 if (!root_window)
1043 return;
1044 if (observers_enabled_)
1045 root_window->AddPreTargetHandler(this);
1046 else
1047 root_window->RemovePreTargetHandler(this);
1048 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698