12a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 22a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 32a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// found in the LICENSE file. 42a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ash/shelf/shelf_layout_manager.h" 62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <algorithm> 82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <cmath> 9868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include <cstring> 10868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include <string> 11868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include <vector> 122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ash/accelerators/accelerator_commands.h" 142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ash/ash_switches.h" 152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ash/root_window_controller.h" 165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ash/screen_util.h" 175c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#include "ash/session/session_state_delegate.h" 185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ash/shelf/shelf.h" 19868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "ash/shelf/shelf_bezel_event_filter.h" 205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ash/shelf/shelf_constants.h" 21b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)#include "ash/shelf/shelf_layout_manager_observer.h" 222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ash/shelf/shelf_widget.h" 232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ash/shell.h" 242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ash/shell_window_ids.h" 252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ash/system/status_area_widget.h" 26c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "ash/wm/gestures/shelf_gesture_handler.h" 2758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "ash/wm/lock_state_controller.h" 28a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "ash/wm/mru_window_tracker.h" 292385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch#include "ash/wm/window_animations.h" 3068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)#include "ash/wm/window_state.h" 312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ash/wm/window_util.h" 32868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "ash/wm/workspace_controller.h" 332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/auto_reset.h" 342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/command_line.h" 35868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/command_line.h" 362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/i18n/rtl.h" 37868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/string_number_conversions.h" 38868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/string_util.h" 39ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch#include "ui/aura/client/cursor_client.h" 40a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ui/aura/window_event_dispatcher.h" 41868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "ui/base/ui_base_switches.h" 422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/compositor/layer.h" 432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/compositor/layer_animation_observer.h" 442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/compositor/layer_animator.h" 452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/compositor/scoped_layer_animation_settings.h" 46d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "ui/events/event.h" 47d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "ui/events/event_handler.h" 482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/gfx/screen.h" 495c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#include "ui/keyboard/keyboard_util.h" 502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/views/widget/widget.h" 51effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#include "ui/wm/public/activation_client.h" 522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace ash { 542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace { 552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Delay before showing the shelf. This is after the mouse stops moving. 572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const int kAutoHideDelayMS = 200; 582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// To avoid hiding the shelf when the mouse transitions from a message bubble 602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// into the shelf, the hit test area is enlarged by this amount of pixels to 612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// keep the shelf from hiding. 622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const int kNotificationBubbleGapHeight = 6; 632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 64bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch// The maximum size of the region on the display opposing the shelf managed by 65bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch// this ShelfLayoutManager which can trigger showing the shelf. 66bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch// For instance: 67bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch// - Primary display is left of secondary display. 68bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch// - Shelf is left aligned 69bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch// - This ShelfLayoutManager manages the shelf for the secondary display. 70bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch// |kMaxAutoHideShowShelfRegionSize| refers to the maximum size of the region 71bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch// from the right edge of the primary display which can trigger showing the 72bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch// auto hidden shelf. The region is used to make it easier to trigger showing 73bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch// the auto hidden shelf when the shelf is on the boundary between displays. 74bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdochconst int kMaxAutoHideShowShelfRegionSize = 10; 75bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch 762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)ui::Layer* GetLayer(views::Widget* widget) { 772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return widget->GetNativeView()->layer(); 782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)bool IsDraggingTrayEnabled() { 812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) static bool dragging_tray_allowed = CommandLine::ForCurrentProcess()-> 822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) HasSwitch(ash::switches::kAshEnableTrayDragging); 832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return dragging_tray_allowed; 842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} // namespace 872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// static 89c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)const int ShelfLayoutManager::kWorkspaceAreaVisibleInset = 2; 90c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 91c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// static 92c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)const int ShelfLayoutManager::kWorkspaceAreaAutoHideInset = 5; 932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// static 952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const int ShelfLayoutManager::kAutoHideSize = 3; 962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 977d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// static 98d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)const int ShelfLayoutManager::kShelfItemInset = 3; 99d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 1002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// ShelfLayoutManager::AutoHideEventFilter ------------------------------------- 1012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Notifies ShelfLayoutManager any time the mouse moves. 1032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class ShelfLayoutManager::AutoHideEventFilter : public ui::EventHandler { 1042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public: 1052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) explicit AutoHideEventFilter(ShelfLayoutManager* shelf); 1062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~AutoHideEventFilter(); 1072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Returns true if the last mouse event was a mouse drag. 1092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool in_mouse_drag() const { return in_mouse_drag_; } 1102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Overridden from ui::EventHandler: 1122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE; 113c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; 1142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private: 1162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ShelfLayoutManager* shelf_; 1172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool in_mouse_drag_; 118c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ShelfGestureHandler gesture_handler_; 1192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(AutoHideEventFilter); 1202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 1212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)ShelfLayoutManager::AutoHideEventFilter::AutoHideEventFilter( 1232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ShelfLayoutManager* shelf) 1242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) : shelf_(shelf), 1252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) in_mouse_drag_(false) { 1262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Shell::GetInstance()->AddPreTargetHandler(this); 1272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 1282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)ShelfLayoutManager::AutoHideEventFilter::~AutoHideEventFilter() { 1302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Shell::GetInstance()->RemovePreTargetHandler(this); 1312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 1322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ShelfLayoutManager::AutoHideEventFilter::OnMouseEvent( 1342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ui::MouseEvent* event) { 1352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // This also checks IsShelfWindow() to make sure we don't attempt to hide the 1362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // shelf if the mouse down occurs on the shelf. 1372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) in_mouse_drag_ = (event->type() == ui::ET_MOUSE_DRAGGED || 1382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) (in_mouse_drag_ && event->type() != ui::ET_MOUSE_RELEASED && 1392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) event->type() != ui::ET_MOUSE_CAPTURE_CHANGED)) && 1402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) !shelf_->IsShelfWindow(static_cast<aura::Window*>(event->target())); 1412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (event->type() == ui::ET_MOUSE_MOVED) 1422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) shelf_->UpdateAutoHideState(); 1432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return; 1442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 1452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 146c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)void ShelfLayoutManager::AutoHideEventFilter::OnGestureEvent( 147c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ui::GestureEvent* event) { 148a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) if (shelf_->IsShelfWindow(static_cast<aura::Window*>(event->target()))) { 149a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) if (gesture_handler_.ProcessGestureEvent(*event)) 150a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) event->StopPropagation(); 151a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) } 152c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 153c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// ShelfLayoutManager:UpdateShelfObserver -------------------------------------- 1552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// UpdateShelfObserver is used to delay updating the background until the 1572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// animation completes. 1582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class ShelfLayoutManager::UpdateShelfObserver 1592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) : public ui::ImplicitAnimationObserver { 1602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public: 1612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) explicit UpdateShelfObserver(ShelfLayoutManager* shelf) : shelf_(shelf) { 1622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) shelf_->update_shelf_observer_ = this; 1632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 1642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void Detach() { 1662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) shelf_ = NULL; 1672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 1682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void OnImplicitAnimationsCompleted() OVERRIDE { 170a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) if (shelf_) 171a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) shelf_->UpdateShelfBackground(BACKGROUND_CHANGE_ANIMATE); 1722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) delete this; 1732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 1742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private: 1762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~UpdateShelfObserver() { 1772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (shelf_) 1782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) shelf_->update_shelf_observer_ = NULL; 1792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 1802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Shelf we're in. NULL if deleted before we're deleted. 1822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ShelfLayoutManager* shelf_; 1832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(UpdateShelfObserver); 1852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 1862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// ShelfLayoutManager ---------------------------------------------------------- 1882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)ShelfLayoutManager::ShelfLayoutManager(ShelfWidget* shelf) 1905f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) : SnapToPixelLayoutManager(shelf->GetNativeView()->parent()), 1915f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) root_window_(shelf->GetNativeView()->GetRootWindow()), 1923551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) updating_bounds_(false), 1932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) auto_hide_behavior_(SHELF_AUTO_HIDE_BEHAVIOR_NEVER), 1942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) alignment_(SHELF_ALIGNMENT_BOTTOM), 1952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) shelf_(shelf), 1962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) workspace_controller_(NULL), 1972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) window_overlaps_shelf_(false), 198bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch mouse_over_shelf_when_auto_hide_timer_started_(false), 199868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) bezel_event_filter_(new ShelfBezelEventFilter(this)), 2002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gesture_drag_status_(GESTURE_DRAG_NONE), 2012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gesture_drag_amount_(0.f), 2022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gesture_drag_auto_hide_state_(SHELF_AUTO_HIDE_SHOWN), 2035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) update_shelf_observer_(NULL), 2045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) duration_override_in_ms_(0) { 2052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Shell::GetInstance()->AddShellObserver(this); 20658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) Shell::GetInstance()->lock_state_controller()->AddObserver(this); 2072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) aura::client::GetActivationClient(root_window_)->AddObserver(this); 208a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch Shell::GetInstance()->session_state_delegate()->AddSessionStateObserver(this); 2092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 2102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)ShelfLayoutManager::~ShelfLayoutManager() { 2122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (update_shelf_observer_) 2132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) update_shelf_observer_->Detach(); 2142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 215b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_, WillDeleteShelf()); 2162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Shell::GetInstance()->RemoveShellObserver(this); 21758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) Shell::GetInstance()->lock_state_controller()->RemoveObserver(this); 2182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) aura::client::GetActivationClient(root_window_)->RemoveObserver(this); 219a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch Shell::GetInstance()-> 220a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch session_state_delegate()->RemoveSessionStateObserver(this); 2212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 2222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ShelfLayoutManager::SetAutoHideBehavior(ShelfAutoHideBehavior behavior) { 2242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (auto_hide_behavior_ == behavior) 2252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return; 2262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) auto_hide_behavior_ = behavior; 2272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) UpdateVisibilityState(); 228b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_, 2297dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch OnAutoHideBehaviorChanged(root_window_, 2307dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch auto_hide_behavior_)); 2317dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch} 2327dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 2337dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochvoid ShelfLayoutManager::PrepareForShutdown() { 2347dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // Clear all event filters, otherwise sometimes those filters may catch 2357dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // synthesized mouse event and cause crashes during the shutdown. 2367dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch set_workspace_controller(NULL); 2377dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch auto_hide_event_filter_.reset(); 2387dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch bezel_event_filter_.reset(); 2392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 2402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)bool ShelfLayoutManager::IsVisible() const { 2427dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // status_area_widget() may be NULL during the shutdown. 2437dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch return shelf_->status_area_widget() && 2447dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch shelf_->status_area_widget()->IsVisible() && 2452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) (state_.visibility_state == SHELF_VISIBLE || 2462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) (state_.visibility_state == SHELF_AUTO_HIDE && 2472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) state_.auto_hide_state == SHELF_AUTO_HIDE_SHOWN)); 2482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 2492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)bool ShelfLayoutManager::SetAlignment(ShelfAlignment alignment) { 2512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (alignment_ == alignment) 2522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return false; 2532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 25458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // This should not be called during the lock screen transitions. 25558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) DCHECK(!Shell::GetInstance()->session_state_delegate()->IsScreenLocked()); 2562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) alignment_ = alignment; 25790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) shelf_->SetAlignment(alignment); 2582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) LayoutShelf(); 2592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return true; 2602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 2612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 26258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)ShelfAlignment ShelfLayoutManager::GetAlignment() const { 26358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // When the screen is locked, the shelf is forced into bottom alignment. 26458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) if (Shell::GetInstance()->session_state_delegate()->IsScreenLocked()) 26558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) return SHELF_ALIGNMENT_BOTTOM; 26658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) return alignment_; 26758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)} 26858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 2692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)gfx::Rect ShelfLayoutManager::GetIdealBounds() { 2702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Rect bounds( 2715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ScreenUtil::GetDisplayBoundsInParent(shelf_->GetNativeView())); 2722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int width = 0, height = 0; 2732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetShelfSize(&width, &height); 2742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return SelectValueForShelfAlignment( 2752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Rect(bounds.x(), bounds.bottom() - height, bounds.width(), height), 2762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Rect(bounds.x(), bounds.y(), width, bounds.height()), 2772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Rect(bounds.right() - width, bounds.y(), width, bounds.height()), 2782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Rect(bounds.x(), bounds.y(), bounds.width(), height)); 2792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 2802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ShelfLayoutManager::LayoutShelf() { 2822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) TargetBounds target_bounds; 2832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CalculateTargetBounds(state_, &target_bounds); 2843551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) UpdateBoundsAndOpacity(target_bounds, false, NULL); 2853551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 2865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (shelf_->shelf()) { 2873551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // This is not part of UpdateBoundsAndOpacity() because 2888bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // SetShelfViewBounds() sets the bounds immediately and does not animate. 2898bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // The height of the ShelfView for a horizontal shelf and the width of 2908bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // the ShelfView for a vertical shelf are set when |shelf_|'s bounds 2913551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // are changed via UpdateBoundsAndOpacity(). This sets the origin and the 2923551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // dimension in the other direction. 2935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) shelf_->shelf()->SetShelfViewBounds( 2945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) target_bounds.shelf_bounds_in_shelf); 2953551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) } 2962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 2972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)ShelfVisibilityState ShelfLayoutManager::CalculateShelfVisibility() { 2992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) switch(auto_hide_behavior_) { 3002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) case SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS: 3012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return SHELF_AUTO_HIDE; 3022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) case SHELF_AUTO_HIDE_BEHAVIOR_NEVER: 3032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return SHELF_VISIBLE; 3042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) case SHELF_AUTO_HIDE_ALWAYS_HIDDEN: 3052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return SHELF_HIDDEN; 3062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 3072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return SHELF_VISIBLE; 3082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 3092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ShelfLayoutManager::UpdateVisibilityState() { 3115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Bail out early when there is no |workspace_controller_|, which happens 3125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // during shutdown after PrepareForShutdown. 3135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (!workspace_controller_) 3145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return; 3155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 31646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) if (Shell::GetInstance()->session_state_delegate()->IsScreenLocked()) { 3172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) SetState(SHELF_VISIBLE); 3187d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) } else { 3192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // TODO(zelidrag): Verify shelf drag animation still shows on the device 3202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // when we are in SHELF_AUTO_HIDE_ALWAYS_HIDDEN. 3212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) WorkspaceWindowState window_state(workspace_controller_->GetWindowState()); 3222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) switch (window_state) { 323a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) case WORKSPACE_WINDOW_STATE_FULL_SCREEN: { 324a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const aura::Window* fullscreen_window = GetRootWindowController( 325a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) root_window_)->GetWindowForFullscreenMode(); 326a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) if (fullscreen_window && wm::GetWindowState(fullscreen_window)-> 327a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) hide_shelf_when_fullscreen()) { 328c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) SetState(SHELF_HIDDEN); 3291e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) } else { 3301e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // The shelf is sometimes not hidden when in immersive fullscreen. 3311e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Force the shelf to be auto hidden in this case. 3321e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) SetState(SHELF_AUTO_HIDE); 333c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 3342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) break; 335a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) } 336a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 3372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) case WORKSPACE_WINDOW_STATE_MAXIMIZED: 3382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) SetState(CalculateShelfVisibility()); 3392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) break; 340a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 3412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) case WORKSPACE_WINDOW_STATE_WINDOW_OVERLAPS_SHELF: 3422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) case WORKSPACE_WINDOW_STATE_DEFAULT: 3432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) SetState(CalculateShelfVisibility()); 3442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) SetWindowOverlapsShelf(window_state == 3452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) WORKSPACE_WINDOW_STATE_WINDOW_OVERLAPS_SHELF); 3462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) break; 3472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 3482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 3492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 3502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ShelfLayoutManager::UpdateAutoHideState() { 3522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ShelfAutoHideState auto_hide_state = 3532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CalculateAutoHideState(state_.visibility_state); 3542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (auto_hide_state != state_.auto_hide_state) { 3552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (auto_hide_state == SHELF_AUTO_HIDE_HIDDEN) { 3562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Hides happen immediately. 3572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) SetState(state_.visibility_state); 3582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } else { 359bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch if (!auto_hide_timer_.IsRunning()) { 360bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch mouse_over_shelf_when_auto_hide_timer_started_ = 361bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch shelf_->GetWindowBoundsInScreen().Contains( 362bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch Shell::GetScreen()->GetCursorScreenPoint()); 363bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch } 3642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) auto_hide_timer_.Start( 3652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) FROM_HERE, 3662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::TimeDelta::FromMilliseconds(kAutoHideDelayMS), 3672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) this, &ShelfLayoutManager::UpdateAutoHideStateNow); 3682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 3692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } else { 370bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch StopAutoHideTimer(); 3712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 3722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 3732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ShelfLayoutManager::SetWindowOverlapsShelf(bool value) { 3752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) window_overlaps_shelf_ = value; 376a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) UpdateShelfBackground(BACKGROUND_CHANGE_ANIMATE); 3772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 3782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 379b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)void ShelfLayoutManager::AddObserver(ShelfLayoutManagerObserver* observer) { 3802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) observers_.AddObserver(observer); 3812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 3822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 383b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)void ShelfLayoutManager::RemoveObserver(ShelfLayoutManagerObserver* observer) { 3842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) observers_.RemoveObserver(observer); 3852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 3862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)//////////////////////////////////////////////////////////////////////////////// 3885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// ShelfLayoutManager, Gesture functions: 3895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 3905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void ShelfLayoutManager::OnGestureEdgeSwipe(const ui::GestureEvent& gesture) { 39123730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) if (visibility_state() == SHELF_AUTO_HIDE) { 39223730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) gesture_drag_auto_hide_state_ = SHELF_AUTO_HIDE_SHOWN; 39323730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) gesture_drag_status_ = GESTURE_DRAG_COMPLETE_IN_PROGRESS; 39423730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) UpdateVisibilityState(); 39523730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) gesture_drag_status_ = GESTURE_DRAG_NONE; 3965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 3975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 3982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ShelfLayoutManager::StartGestureDrag(const ui::GestureEvent& gesture) { 4002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gesture_drag_status_ = GESTURE_DRAG_IN_PROGRESS; 4012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gesture_drag_amount_ = 0.f; 4022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gesture_drag_auto_hide_state_ = visibility_state() == SHELF_AUTO_HIDE ? 4032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) auto_hide_state() : SHELF_AUTO_HIDE_SHOWN; 404a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) UpdateShelfBackground(BACKGROUND_CHANGE_ANIMATE); 4052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 4062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)ShelfLayoutManager::DragState ShelfLayoutManager::UpdateGestureDrag( 4082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const ui::GestureEvent& gesture) { 4092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool horizontal = IsHorizontalAlignment(); 4102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gesture_drag_amount_ += horizontal ? gesture.details().scroll_y() : 4112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gesture.details().scroll_x(); 4122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) LayoutShelf(); 4132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Start reveling the status menu when: 4152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // - dragging up on an already visible shelf 4162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // - dragging up on a hidden shelf, but it is currently completely visible. 4172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (horizontal && gesture.details().scroll_y() < 0) { 4182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int min_height = 0; 4192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_HIDDEN && shelf_) 4202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) min_height = shelf_->GetContentsView()->GetPreferredSize().height(); 4212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (min_height < shelf_->GetWindowBoundsInScreen().height() && 4232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gesture.root_location().x() >= 4242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) shelf_->status_area_widget()->GetWindowBoundsInScreen().x() && 4252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) IsDraggingTrayEnabled()) 4262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return DRAG_TRAY; 4272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 4282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return DRAG_SHELF; 4302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 4312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ShelfLayoutManager::CompleteGestureDrag(const ui::GestureEvent& gesture) { 4332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool horizontal = IsHorizontalAlignment(); 4342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool should_change = false; 4352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (gesture.type() == ui::ET_GESTURE_SCROLL_END) { 4362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // The visibility of the shelf changes only if the shelf was dragged X% 4372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // along the correct axis. If the shelf was already visible, then the 4382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // direction of the drag does not matter. 4392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const float kDragHideThreshold = 0.4f; 4402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Rect bounds = GetIdealBounds(); 4412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) float drag_ratio = fabs(gesture_drag_amount_) / 4422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) (horizontal ? bounds.height() : bounds.width()); 4432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_SHOWN) { 4442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) should_change = drag_ratio > kDragHideThreshold; 4452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } else { 4462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool correct_direction = false; 44758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) switch (GetAlignment()) { 4482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) case SHELF_ALIGNMENT_BOTTOM: 4492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) case SHELF_ALIGNMENT_RIGHT: 4502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) correct_direction = gesture_drag_amount_ < 0; 4512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) break; 4522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) case SHELF_ALIGNMENT_LEFT: 4532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) case SHELF_ALIGNMENT_TOP: 4542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) correct_direction = gesture_drag_amount_ > 0; 4552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) break; 4562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 4572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) should_change = correct_direction && drag_ratio > kDragHideThreshold; 4582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 4592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } else if (gesture.type() == ui::ET_SCROLL_FLING_START) { 4602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_SHOWN) { 4612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) should_change = horizontal ? fabs(gesture.details().velocity_y()) > 0 : 4622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) fabs(gesture.details().velocity_x()) > 0; 4632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } else { 4642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) should_change = SelectValueForShelfAlignment( 4652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gesture.details().velocity_y() < 0, 4662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gesture.details().velocity_x() > 0, 4672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gesture.details().velocity_x() < 0, 4682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gesture.details().velocity_y() > 0); 4692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 4702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } else { 4712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) NOTREACHED(); 4722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 4732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (!should_change) { 4752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CancelGestureDrag(); 4762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return; 4772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 47890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) if (shelf_) { 47990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) shelf_->Deactivate(); 48090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) shelf_->status_area_widget()->Deactivate(); 48190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 4822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gesture_drag_auto_hide_state_ = 4832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_SHOWN ? 4842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) SHELF_AUTO_HIDE_HIDDEN : SHELF_AUTO_HIDE_SHOWN; 4857d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) ShelfAutoHideBehavior new_auto_hide_behavior = 4867d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_SHOWN ? 4877d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) SHELF_AUTO_HIDE_BEHAVIOR_NEVER : SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS; 4887d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 4891e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // When in fullscreen and the shelf is forced to be auto hidden, the auto hide 4901e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // behavior affects neither the visibility state nor the auto hide state. Set 4911e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // |gesture_drag_status_| to GESTURE_DRAG_COMPLETE_IN_PROGRESS to set the auto 4921e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // hide state to |gesture_drag_auto_hide_state_|. 4937d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) gesture_drag_status_ = GESTURE_DRAG_COMPLETE_IN_PROGRESS; 4947d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) if (auto_hide_behavior_ != new_auto_hide_behavior) 4957d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) SetAutoHideBehavior(new_auto_hide_behavior); 4967d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) else 4972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) UpdateVisibilityState(); 4987d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) gesture_drag_status_ = GESTURE_DRAG_NONE; 4992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 5002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ShelfLayoutManager::CancelGestureDrag() { 5023551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) gesture_drag_status_ = GESTURE_DRAG_CANCEL_IN_PROGRESS; 5032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) UpdateVisibilityState(); 5043551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) gesture_drag_status_ = GESTURE_DRAG_NONE; 5052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 5062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void ShelfLayoutManager::SetAnimationDurationOverride( 5085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) int duration_override_in_ms) { 5095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) duration_override_in_ms_ = duration_override_in_ms; 5105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 5115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 5122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)//////////////////////////////////////////////////////////////////////////////// 5132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// ShelfLayoutManager, aura::LayoutManager implementation: 5142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ShelfLayoutManager::OnWindowResized() { 5162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) LayoutShelf(); 5172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 5182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ShelfLayoutManager::SetChildBounds(aura::Window* child, 5202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const gfx::Rect& requested_bounds) { 5215f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) SnapToPixelLayoutManager::SetChildBounds(child, requested_bounds); 5222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // We may contain other widgets (such as frame maximize bubble) but they don't 5232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // effect the layout in anyway. 5243551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) if (!updating_bounds_ && 5252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ((shelf_->GetNativeView() == child) || 5262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) (shelf_->status_area_widget()->GetNativeView() == child))) { 5272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) LayoutShelf(); 5282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 5292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 5302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ShelfLayoutManager::OnLockStateChanged(bool locked) { 53258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // Force the shelf to layout for alignment (bottom if locked, restore 53358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // the previous alignment otherwise). 534a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) state_.is_screen_locked = locked; 53558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) shelf_->SetAlignment(locked ? SHELF_ALIGNMENT_BOTTOM : alignment_); 5362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) UpdateVisibilityState(); 53758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) LayoutShelf(); 5382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 5392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ShelfLayoutManager::OnWindowActivated(aura::Window* gained_active, 5412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) aura::Window* lost_active) { 5422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) UpdateAutoHideStateNow(); 5432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 5442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)bool ShelfLayoutManager::IsHorizontalAlignment() const { 54658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) return GetAlignment() == SHELF_ALIGNMENT_BOTTOM || 54758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) GetAlignment() == SHELF_ALIGNMENT_TOP; 5482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 5492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// static 5515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)ShelfLayoutManager* ShelfLayoutManager::ForShelf(aura::Window* window) { 5525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ShelfWidget* shelf = RootWindowController::ForShelf(window)->shelf(); 5532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return shelf ? shelf->shelf_layout_manager() : NULL; 5542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 5552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)//////////////////////////////////////////////////////////////////////////////// 5572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// ShelfLayoutManager, private: 5582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)ShelfLayoutManager::TargetBounds::TargetBounds() : opacity(0.0f) {} 5602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)ShelfLayoutManager::TargetBounds::~TargetBounds() {} 5612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ShelfLayoutManager::SetState(ShelfVisibilityState visibility_state) { 563c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) if (!shelf_->GetNativeView()) 564c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) return; 565c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 5662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) State state; 5672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) state.visibility_state = visibility_state; 5682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) state.auto_hide_state = CalculateAutoHideState(visibility_state); 5697dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch state.window_state = workspace_controller_ ? 5707dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch workspace_controller_->GetWindowState() : WORKSPACE_WINDOW_STATE_DEFAULT; 5712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5723551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Force an update because gesture drags affect the shelf bounds and we 5733551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // should animate back to the normal bounds at the end of a gesture. 5743551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) bool force_update = 5753551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) (gesture_drag_status_ == GESTURE_DRAG_CANCEL_IN_PROGRESS || 5763551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) gesture_drag_status_ == GESTURE_DRAG_COMPLETE_IN_PROGRESS); 5773551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 5783551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) if (!force_update && state_.Equals(state)) 5792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return; // Nothing changed. 5802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 581b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_, 5822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) WillChangeVisibilityState(visibility_state)); 5832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (state.visibility_state == SHELF_AUTO_HIDE) { 5852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // When state is SHELF_AUTO_HIDE we need to track when the mouse is over the 5865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // shelf to unhide it. AutoHideEventFilter does that for us. 587868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) if (!auto_hide_event_filter_) 588868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) auto_hide_event_filter_.reset(new AutoHideEventFilter(this)); 5892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } else { 590868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) auto_hide_event_filter_.reset(NULL); 5912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 5922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 593bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch StopAutoHideTimer(); 5942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) State old_state = state_; 5962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) state_ = state; 5972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 598a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) BackgroundAnimatorChangeType change_type = BACKGROUND_CHANGE_ANIMATE; 599ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch bool delay_background_change = false; 600ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch 601ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch // Do not animate the background when: 602ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch // - Going from a hidden / auto hidden shelf in fullscreen to a visible shelf 603ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch // in maximized mode. 604ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch // - Going from an auto hidden shelf in maximized mode to a visible shelf in 605ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch // maximized mode. 606ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch if (state.visibility_state == SHELF_VISIBLE && 607ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch state.window_state == WORKSPACE_WINDOW_STATE_MAXIMIZED && 608ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch old_state.visibility_state != SHELF_VISIBLE) { 609a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) change_type = BACKGROUND_CHANGE_IMMEDIATE; 610ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch } else { 611ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch // Delay the animation when the shelf was hidden, and has just been made 612ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch // visible (e.g. using a gesture-drag). 613ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch if (state.visibility_state == SHELF_VISIBLE && 614ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch old_state.visibility_state == SHELF_AUTO_HIDE && 615ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch old_state.auto_hide_state == SHELF_AUTO_HIDE_HIDDEN) { 616ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch delay_background_change = true; 617ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch } 618ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch } 619ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch 620ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch if (delay_background_change) { 6212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (update_shelf_observer_) 6222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) update_shelf_observer_->Detach(); 6232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // UpdateShelfBackground deletes itself when the animation is done. 6242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) update_shelf_observer_ = new UpdateShelfObserver(this); 625ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch } else { 626ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch UpdateShelfBackground(change_type); 6272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 628ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch 629ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch shelf_->SetDimsShelf( 630ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch state.visibility_state == SHELF_VISIBLE && 631ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch state.window_state == WORKSPACE_WINDOW_STATE_MAXIMIZED); 632ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch 6333551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) TargetBounds target_bounds; 6343551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) CalculateTargetBounds(state_, &target_bounds); 6353551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) UpdateBoundsAndOpacity(target_bounds, true, 6363551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) delay_background_change ? update_shelf_observer_ : NULL); 637558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch 638558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch // OnAutoHideStateChanged Should be emitted when: 639558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch // - firstly state changed to auto-hide from other state 640558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch // - or, auto_hide_state has changed 641558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch if ((old_state.visibility_state != state_.visibility_state && 642558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch state_.visibility_state == SHELF_AUTO_HIDE) || 643558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch old_state.auto_hide_state != state_.auto_hide_state) { 644558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_, 645558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch OnAutoHideStateChanged(state_.auto_hide_state)); 646558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch } 6472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 6482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6493551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)void ShelfLayoutManager::UpdateBoundsAndOpacity( 6503551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) const TargetBounds& target_bounds, 6513551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) bool animate, 6523551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) ui::ImplicitAnimationObserver* observer) { 6533551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) base::AutoReset<bool> auto_reset_updating_bounds(&updating_bounds_, true); 6541320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci { 6551320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci ui::ScopedLayerAnimationSettings shelf_animation_setter( 6561320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci GetLayer(shelf_)->GetAnimator()); 6571320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci ui::ScopedLayerAnimationSettings status_animation_setter( 6581320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci GetLayer(shelf_->status_area_widget())->GetAnimator()); 6591320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci if (animate) { 6601320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci int duration = duration_override_in_ms_ ? duration_override_in_ms_ : 6611320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci kCrossFadeDurationMS; 6621320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci shelf_animation_setter.SetTransitionDuration( 6631320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci base::TimeDelta::FromMilliseconds(duration)); 6641320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci shelf_animation_setter.SetTweenType(gfx::Tween::EASE_OUT); 6651320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci shelf_animation_setter.SetPreemptionStrategy( 6661320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); 6671320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci status_animation_setter.SetTransitionDuration( 6681320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci base::TimeDelta::FromMilliseconds(duration)); 6691320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci status_animation_setter.SetTweenType(gfx::Tween::EASE_OUT); 6701320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci status_animation_setter.SetPreemptionStrategy( 6711320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); 6721320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci } else { 6731320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci StopAnimating(); 6741320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci shelf_animation_setter.SetTransitionDuration(base::TimeDelta()); 6751320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci status_animation_setter.SetTransitionDuration(base::TimeDelta()); 6761320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci } 6771320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci if (observer) 6781320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci status_animation_setter.AddObserver(observer); 6791320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 6801320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci GetLayer(shelf_)->SetOpacity(target_bounds.opacity); 6811320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci shelf_->SetBounds(ScreenUtil::ConvertRectToScreen( 6821320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci shelf_->GetNativeView()->parent(), 6831320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci target_bounds.shelf_bounds_in_root)); 6841320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 6851320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci GetLayer(shelf_->status_area_widget())->SetOpacity( 6861320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci target_bounds.status_opacity); 6871320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 6881320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // Having a window which is visible but does not have an opacity is an 6891320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // illegal state. We therefore hide the shelf here if required. 6901320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci if (!target_bounds.status_opacity) 6911320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci shelf_->status_area_widget()->Hide(); 6921320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // Setting visibility during an animation causes the visibility property to 6931320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // animate. Override the animation settings to immediately set the 6941320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // visibility property. Opacity will still animate. 6951320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 6961320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // TODO(harrym): Once status area widget is a child view of shelf 6971320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // this can be simplified. 6981320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci gfx::Rect status_bounds = target_bounds.status_bounds_in_shelf; 6991320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci status_bounds.set_x(status_bounds.x() + 7001320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci target_bounds.shelf_bounds_in_root.x()); 7011320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci status_bounds.set_y(status_bounds.y() + 7021320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci target_bounds.shelf_bounds_in_root.y()); 7031320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci shelf_->status_area_widget()->SetBounds( 7041320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci ScreenUtil::ConvertRectToScreen( 7051320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci shelf_->status_area_widget()->GetNativeView()->parent(), 7061320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci status_bounds)); 7071320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci SessionStateDelegate* session_state_delegate = 7081320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci Shell::GetInstance()->session_state_delegate(); 7091320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci if (!state_.is_screen_locked) { 7101320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci gfx::Insets insets; 7111320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // If user session is blocked (login to new user session or add user to 7121320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // the existing session - multi-profile) then give 100% of work area only 7131320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // if keyboard is not shown. 7141320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci if (!session_state_delegate->IsUserSessionBlocked() || 7151320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci !keyboard_bounds_.IsEmpty()) { 7161320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci insets = target_bounds.work_area_insets; 7171320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci } 7181320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci Shell::GetInstance()->SetDisplayWorkAreaInsets(root_window_, insets); 719a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch } 720a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) } 7211320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 7221320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // Setting visibility during an animation causes the visibility property to 7231320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // animate. Set the visibility property without an animation. 7241320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci if (target_bounds.status_opacity) 7251320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci shelf_->status_area_widget()->Show(); 7263551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)} 7273551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 7282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ShelfLayoutManager::StopAnimating() { 7292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetLayer(shelf_)->GetAnimator()->StopAnimating(); 7302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetLayer(shelf_->status_area_widget())->GetAnimator()->StopAnimating(); 7312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 7322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 7332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ShelfLayoutManager::GetShelfSize(int* width, int* height) { 7342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) *width = *height = 0; 7352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Size status_size( 7362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) shelf_->status_area_widget()->GetWindowBoundsInScreen().size()); 7372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (IsHorizontalAlignment()) 738a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch *height = kShelfSize; 7392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) else 740a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch *width = kShelfSize; 7412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 7422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 7432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ShelfLayoutManager::AdjustBoundsBasedOnAlignment(int inset, 7442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Rect* bounds) const { 7452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bounds->Inset(SelectValueForShelfAlignment( 7462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Insets(0, 0, inset, 0), 7472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Insets(0, inset, 0, 0), 7482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Insets(0, 0, 0, inset), 7492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Insets(inset, 0, 0, 0))); 7502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 7512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 7522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ShelfLayoutManager::CalculateTargetBounds( 7532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const State& state, 7542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) TargetBounds* target_bounds) { 7555c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu const gfx::Rect available_bounds(root_window_->bounds()); 7562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Rect status_size( 7572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) shelf_->status_area_widget()->GetWindowBoundsInScreen().size()); 7582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int shelf_width = 0, shelf_height = 0; 7592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetShelfSize(&shelf_width, &shelf_height); 7602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (IsHorizontalAlignment()) 7612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) shelf_width = available_bounds.width(); 7622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) else 7632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) shelf_height = available_bounds.height(); 7642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 7652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (state.visibility_state == SHELF_AUTO_HIDE && 7662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) state.auto_hide_state == SHELF_AUTO_HIDE_HIDDEN) { 767c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Auto-hidden shelf always starts with the default size. If a gesture-drag 768c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // is in progress, then the call to UpdateTargetBoundsForGesture() below 769c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // takes care of setting the height properly. 770c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) if (IsHorizontalAlignment()) 771c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) shelf_height = kAutoHideSize; 772c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) else 773c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) shelf_width = kAutoHideSize; 774c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } else if (state.visibility_state == SHELF_HIDDEN || 7755c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu (!keyboard_bounds_.IsEmpty() && !keyboard::IsKeyboardOverscrollEnabled())) 7765c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu { 7772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (IsHorizontalAlignment()) 7782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) shelf_height = 0; 7792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) else 7802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) shelf_width = 0; 7812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 782c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 7835c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu int bottom_shelf_vertical_offset = available_bounds.bottom(); 7845c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu if (keyboard_bounds_.IsEmpty()) 7855c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu bottom_shelf_vertical_offset -= shelf_height; 7865c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu else 7875c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu bottom_shelf_vertical_offset -= keyboard_bounds_.height(); 7885c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 7892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) target_bounds->shelf_bounds_in_root = SelectValueForShelfAlignment( 7905c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu gfx::Rect(available_bounds.x(), bottom_shelf_vertical_offset, 7912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) available_bounds.width(), shelf_height), 7922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Rect(available_bounds.x(), available_bounds.y(), 7932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) shelf_width, available_bounds.height()), 7942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Rect(available_bounds.right() - shelf_width, available_bounds.y(), 7952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) shelf_width, available_bounds.height()), 7962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Rect(available_bounds.x(), available_bounds.y(), 7972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) available_bounds.width(), shelf_height)); 7982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 799a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch if (IsHorizontalAlignment()) 800a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch status_size.set_height(kShelfSize); 801a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch else 802a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch status_size.set_width(kShelfSize); 803ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch 8042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) target_bounds->status_bounds_in_shelf = SelectValueForShelfAlignment( 8052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Rect(base::i18n::IsRTL() ? 0 : shelf_width - status_size.width(), 806a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 0, status_size.width(), status_size.height()), 807a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch gfx::Rect(shelf_width - status_size.width(), 8082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) shelf_height - status_size.height(), status_size.width(), 8092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) status_size.height()), 810a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch gfx::Rect(0, shelf_height - status_size.height(), 8112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) status_size.width(), status_size.height()), 8122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Rect(base::i18n::IsRTL() ? 0 : shelf_width - status_size.width(), 813a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch shelf_height - status_size.height(), 8142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) status_size.width(), status_size.height())); 8152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 8162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) target_bounds->work_area_insets = SelectValueForShelfAlignment( 8172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Insets(0, 0, GetWorkAreaSize(state, shelf_height), 0), 8182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Insets(0, GetWorkAreaSize(state, shelf_width), 0, 0), 8192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Insets(0, 0, 0, GetWorkAreaSize(state, shelf_width)), 8202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Insets(GetWorkAreaSize(state, shelf_height), 0, 0, 0)); 8212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 822ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch // TODO(varkha): The functionality of managing insets for display areas 823ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch // should probably be pushed to a separate component. This would simplify or 824ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch // remove entirely the dependency on keyboard and dock. 825ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch 8265c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu if (!keyboard_bounds_.IsEmpty() && !keyboard::IsKeyboardOverscrollEnabled()) { 8275c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // Also push in the work area inset for the keyboard if it is visible. 828ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch gfx::Insets keyboard_insets(0, 0, keyboard_bounds_.height(), 0); 829ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch target_bounds->work_area_insets += keyboard_insets; 830ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch } 831ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch 832ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch // Also push in the work area inset for the dock if it is visible. 833ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch if (!dock_bounds_.IsEmpty()) { 834ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch gfx::Insets dock_insets( 835ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch 0, (dock_bounds_.x() > 0 ? 0 : dock_bounds_.width()), 836ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch 0, (dock_bounds_.x() > 0 ? dock_bounds_.width() : 0)); 837ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch target_bounds->work_area_insets += dock_insets; 838c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 839c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 8402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) target_bounds->opacity = 8417d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) (gesture_drag_status_ == GESTURE_DRAG_IN_PROGRESS || 8422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) state.visibility_state == SHELF_VISIBLE || 8432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) state.visibility_state == SHELF_AUTO_HIDE) ? 1.0f : 0.0f; 844eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch target_bounds->status_opacity = 845eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch (state.visibility_state == SHELF_AUTO_HIDE && 846ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch state.auto_hide_state == SHELF_AUTO_HIDE_HIDDEN && 847ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch gesture_drag_status_ != GESTURE_DRAG_IN_PROGRESS) ? 848eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 0.0f : target_bounds->opacity; 849c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 8502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (gesture_drag_status_ == GESTURE_DRAG_IN_PROGRESS) 8512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) UpdateTargetBoundsForGesture(target_bounds); 852c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 853c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // This needs to happen after calling UpdateTargetBoundsForGesture(), because 854c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // that can change the size of the shelf. 8555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) target_bounds->shelf_bounds_in_shelf = SelectValueForShelfAlignment( 8568bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) gfx::Rect(0, 0, 8578bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) shelf_width - status_size.width(), 8588bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) target_bounds->shelf_bounds_in_root.height()), 85990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) gfx::Rect(0, 0, target_bounds->shelf_bounds_in_root.width(), 86090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) shelf_height - status_size.height()), 86190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) gfx::Rect(0, 0, target_bounds->shelf_bounds_in_root.width(), 86290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) shelf_height - status_size.height()), 8638bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) gfx::Rect(0, 0, 8648bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) shelf_width - status_size.width(), 8658bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) target_bounds->shelf_bounds_in_root.height())); 8662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 8672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 8682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ShelfLayoutManager::UpdateTargetBoundsForGesture( 8692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) TargetBounds* target_bounds) const { 8702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CHECK_EQ(GESTURE_DRAG_IN_PROGRESS, gesture_drag_status_); 8712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool horizontal = IsHorizontalAlignment(); 8722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const gfx::Rect& available_bounds(root_window_->bounds()); 8732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int resistance_free_region = 0; 8742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 8752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_HIDDEN && 8762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) visibility_state() == SHELF_AUTO_HIDE && 8772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) auto_hide_state() != SHELF_AUTO_HIDE_SHOWN) { 8782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // If the shelf was hidden when the drag started (and the state hasn't 8792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // changed since then, e.g. because the tray-menu was shown because of the 8802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // drag), then allow the drag some resistance-free region at first to make 8812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // sure the shelf sticks with the finger until the shelf is visible. 882a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch resistance_free_region = kShelfSize - kAutoHideSize; 8832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 8842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 8852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool resist = SelectValueForShelfAlignment( 8862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gesture_drag_amount_ < -resistance_free_region, 8872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gesture_drag_amount_ > resistance_free_region, 8882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gesture_drag_amount_ < -resistance_free_region, 8892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gesture_drag_amount_ > resistance_free_region); 8902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 8912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) float translate = 0.f; 8922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (resist) { 8932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) float diff = fabsf(gesture_drag_amount_) - resistance_free_region; 8942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) diff = std::min(diff, sqrtf(diff)); 8952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (gesture_drag_amount_ < 0) 8962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) translate = -resistance_free_region - diff; 8972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) else 8982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) translate = resistance_free_region + diff; 8992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } else { 9002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) translate = gesture_drag_amount_; 9012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 9022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 9032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (horizontal) { 9045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Move and size the shelf with the gesture. 905c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) int shelf_height = target_bounds->shelf_bounds_in_root.height() - translate; 906c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) shelf_height = std::max(shelf_height, kAutoHideSize); 907c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) target_bounds->shelf_bounds_in_root.set_height(shelf_height); 90858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) if (GetAlignment() == SHELF_ALIGNMENT_BOTTOM) { 909c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) target_bounds->shelf_bounds_in_root.set_y( 910c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) available_bounds.bottom() - shelf_height); 9112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 9122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 913a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch target_bounds->status_bounds_in_shelf.set_y(0); 9142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } else { 9155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Move and size the shelf with the gesture. 91690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) int shelf_width = target_bounds->shelf_bounds_in_root.width(); 91758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) bool right_aligned = GetAlignment() == SHELF_ALIGNMENT_RIGHT; 91858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) if (right_aligned) 91990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) shelf_width -= translate; 92090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) else 92190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) shelf_width += translate; 922c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) shelf_width = std::max(shelf_width, kAutoHideSize); 923c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) target_bounds->shelf_bounds_in_root.set_width(shelf_width); 92458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) if (right_aligned) { 92590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) target_bounds->shelf_bounds_in_root.set_x( 926c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) available_bounds.right() - shelf_width); 9272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 9282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 929a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch if (right_aligned) 930a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch target_bounds->status_bounds_in_shelf.set_x(0); 931a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch else 932a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch target_bounds->status_bounds_in_shelf.set_x( 933a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch target_bounds->shelf_bounds_in_root.width() - 934a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch kShelfSize); 9352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 9362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 9372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 9382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ShelfLayoutManager::UpdateShelfBackground( 939a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) BackgroundAnimatorChangeType type) { 940a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const ShelfBackgroundType background_type(GetShelfBackgroundType()); 941a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) shelf_->SetPaintsBackground(background_type, type); 942a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_, 943a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) OnBackgroundUpdated(background_type, type)); 9442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 9452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 9467dbb3d5cf0c15f500944d211057644d6a2f37371Ben MurdochShelfBackgroundType ShelfLayoutManager::GetShelfBackgroundType() const { 9477dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch if (state_.visibility_state != SHELF_AUTO_HIDE && 9487dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch state_.window_state == WORKSPACE_WINDOW_STATE_MAXIMIZED) { 9497dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch return SHELF_BACKGROUND_MAXIMIZED; 9507dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch } 9517dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 9527dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch if (gesture_drag_status_ == GESTURE_DRAG_IN_PROGRESS || 9532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) (!state_.is_screen_locked && window_overlaps_shelf_) || 9547dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch (state_.visibility_state == SHELF_AUTO_HIDE)) { 9557dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch return SHELF_BACKGROUND_OVERLAP; 9567dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch } 9577dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 9587dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch return SHELF_BACKGROUND_DEFAULT; 9592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 9602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 9612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ShelfLayoutManager::UpdateAutoHideStateNow() { 9622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) SetState(state_.visibility_state); 963bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch 964bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch // If the state did not change, the auto hide timer may still be running. 965bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch StopAutoHideTimer(); 966bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch} 967bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch 968bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdochvoid ShelfLayoutManager::StopAutoHideTimer() { 969bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch auto_hide_timer_.Stop(); 970bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch mouse_over_shelf_when_auto_hide_timer_started_ = false; 971bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch} 972bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch 973bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdochgfx::Rect ShelfLayoutManager::GetAutoHideShowShelfRegionInScreen() const { 974bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch gfx::Rect shelf_bounds_in_screen = shelf_->GetWindowBoundsInScreen(); 975bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch gfx::Vector2d offset = SelectValueForShelfAlignment( 976bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch gfx::Vector2d(0, shelf_bounds_in_screen.height()), 977bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch gfx::Vector2d(-kMaxAutoHideShowShelfRegionSize, 0), 978bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch gfx::Vector2d(shelf_bounds_in_screen.width(), 0), 979bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch gfx::Vector2d(0, -kMaxAutoHideShowShelfRegionSize)); 980bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch 981bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch gfx::Rect show_shelf_region_in_screen = shelf_bounds_in_screen; 982bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch show_shelf_region_in_screen += offset; 983bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch if (IsHorizontalAlignment()) 984bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch show_shelf_region_in_screen.set_height(kMaxAutoHideShowShelfRegionSize); 985bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch else 986bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch show_shelf_region_in_screen.set_width(kMaxAutoHideShowShelfRegionSize); 987bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch 988bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch // TODO: Figure out if we need any special handling when the keyboard is 989bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch // visible. 990bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch return show_shelf_region_in_screen; 9912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 9922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 9932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)ShelfAutoHideState ShelfLayoutManager::CalculateAutoHideState( 9942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ShelfVisibilityState visibility_state) const { 9952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (visibility_state != SHELF_AUTO_HIDE || !shelf_) 9962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return SHELF_AUTO_HIDE_HIDDEN; 9972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 9982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Shell* shell = Shell::GetInstance(); 9992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (shell->GetAppListTargetVisibility()) 10002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return SHELF_AUTO_HIDE_SHOWN; 10012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 10022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (shelf_->status_area_widget() && 10035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) shelf_->status_area_widget()->ShouldShowShelf()) 10042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return SHELF_AUTO_HIDE_SHOWN; 10052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 10065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (shelf_->shelf() && shelf_->shelf()->IsShowingMenu()) 10072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return SHELF_AUTO_HIDE_SHOWN; 10082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 10095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (shelf_->shelf() && shelf_->shelf()->IsShowingOverflowBubble()) 10102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return SHELF_AUTO_HIDE_SHOWN; 10112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 10120529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch if (shelf_->IsActive() || 10130529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch (shelf_->status_area_widget() && 10140529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch shelf_->status_area_widget()->IsActive())) 10152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return SHELF_AUTO_HIDE_SHOWN; 10162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1017ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch const std::vector<aura::Window*> windows = 1018ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch ash::MruWindowTracker::BuildWindowList(false); 1019ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch 1020ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch // Process the window list and check if there are any visible windows. 1021ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch bool visible_window = false; 1022ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch for (size_t i = 0; i < windows.size(); ++i) { 1023ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch if (windows[i] && windows[i]->IsVisible() && 102468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) !wm::GetWindowState(windows[i])->IsMinimized() && 1025ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch root_window_ == windows[i]->GetRootWindow()) { 1026ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch visible_window = true; 1027ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch break; 1028ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch } 1029ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch } 1030ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch // If there are no visible windows do not hide the shelf. 1031ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch if (!visible_window) 1032ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch return SHELF_AUTO_HIDE_SHOWN; 1033ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch 1034ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch if (gesture_drag_status_ == GESTURE_DRAG_COMPLETE_IN_PROGRESS) 1035ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch return gesture_drag_auto_hide_state_; 1036ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch 10372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Don't show if the user is dragging the mouse. 1038868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) if (auto_hide_event_filter_.get() && auto_hide_event_filter_->in_mouse_drag()) 10392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return SHELF_AUTO_HIDE_HIDDEN; 10402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1041ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch // Ignore the mouse position if mouse events are disabled. 1042ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch aura::client::CursorClient* cursor_client = aura::client::GetCursorClient( 1043ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch shelf_->GetNativeWindow()->GetRootWindow()); 1044ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch if (!cursor_client->IsMouseEventsEnabled()) 1045ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch return SHELF_AUTO_HIDE_HIDDEN; 1046ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch 10472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Rect shelf_region = shelf_->GetWindowBoundsInScreen(); 10482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (shelf_->status_area_widget() && 10492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) shelf_->status_area_widget()->IsMessageBubbleShown() && 10502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) IsVisible()) { 10512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Increase the the hit test area to prevent the shelf from disappearing 10522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // when the mouse is over the bubble gap. 105358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) ShelfAlignment alignment = GetAlignment(); 105458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) shelf_region.Inset(alignment == SHELF_ALIGNMENT_RIGHT ? 10552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) -kNotificationBubbleGapHeight : 0, 105658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) alignment == SHELF_ALIGNMENT_BOTTOM ? 10572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) -kNotificationBubbleGapHeight : 0, 105858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) alignment == SHELF_ALIGNMENT_LEFT ? 10592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) -kNotificationBubbleGapHeight : 0, 106058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) alignment == SHELF_ALIGNMENT_TOP ? 10612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) -kNotificationBubbleGapHeight : 0); 10622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 10632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1064bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch gfx::Point cursor_position_in_screen = 1065bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch Shell::GetScreen()->GetCursorScreenPoint(); 1066bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch if (shelf_region.Contains(cursor_position_in_screen)) 1067bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch return SHELF_AUTO_HIDE_SHOWN; 1068bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch 1069bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch // When the shelf is auto hidden and the shelf is on the boundary between two 1070bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch // displays, it is hard to trigger showing the shelf. For instance, if a 1071bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch // user's primary display is left of their secondary display, it is hard to 1072bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch // unautohide a left aligned shelf on the secondary display. 1073bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch // It is hard because: 1074bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch // - It is hard to stop the cursor in the shelf "light bar" and not overshoot. 1075bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch // - The cursor is warped to the other display if the cursor gets to the edge 1076bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch // of the display. 1077bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch // Show the shelf if the cursor started on the shelf and the user overshot the 1078bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch // shelf slightly to make it easier to show the shelf in this situation. We 1079bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch // do not check |auto_hide_timer_|.IsRunning() because it returns false when 1080bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch // the timer's task is running. 1081bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch if ((state_.auto_hide_state == SHELF_AUTO_HIDE_SHOWN || 1082bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch mouse_over_shelf_when_auto_hide_timer_started_) && 1083bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch GetAutoHideShowShelfRegionInScreen().Contains( 1084bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch cursor_position_in_screen)) { 10852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return SHELF_AUTO_HIDE_SHOWN; 1086bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch } 10872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1088ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch return SHELF_AUTO_HIDE_HIDDEN; 10892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 10902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 10912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)bool ShelfLayoutManager::IsShelfWindow(aura::Window* window) { 10922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (!window) 10932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return false; 109490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) return (shelf_ && shelf_->GetNativeWindow()->Contains(window)) || 109590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) (shelf_->status_area_widget() && 109690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) shelf_->status_area_widget()->GetNativeWindow()->Contains(window)); 10972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 10982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 10992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)int ShelfLayoutManager::GetWorkAreaSize(const State& state, int size) const { 11002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (state.visibility_state == SHELF_VISIBLE) 11012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return size; 11022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (state.visibility_state == SHELF_AUTO_HIDE) 11032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return kAutoHideSize; 11042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return 0; 11052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 11062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1107c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdochvoid ShelfLayoutManager::OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) { 1108c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch bool keyboard_is_about_to_hide = false; 1109c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch if (new_bounds.IsEmpty() && !keyboard_bounds_.IsEmpty()) 1110c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch keyboard_is_about_to_hide = true; 1111c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch 1112c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch keyboard_bounds_ = new_bounds; 1113c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) OnWindowResized(); 1114c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch 1115c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch SessionStateDelegate* session_state_delegate = 1116c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch Shell::GetInstance()->session_state_delegate(); 1117c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch 1118c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // On login screen if keyboard has been just hidden, update bounds just once 1119c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // but ignore target_bounds.work_area_insets since shelf overlaps with login 1120c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // window. 1121a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch if (session_state_delegate->IsUserSessionBlocked() && 1122c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch keyboard_is_about_to_hide) { 1123c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch Shell::GetInstance()->SetDisplayWorkAreaInsets(root_window_, gfx::Insets()); 1124c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch } 1125c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 1126c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1127ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdochvoid ShelfLayoutManager::OnDockBoundsChanging( 11284e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) const gfx::Rect& dock_bounds, 11294e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) DockedWindowLayoutManagerObserver::Reason reason) { 11304e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // Skip shelf layout in case docked notification originates from this class. 11314e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) if (reason == DISPLAY_INSETS_CHANGED) 11324e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) return; 1133ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch if (dock_bounds_ != dock_bounds) { 1134ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch dock_bounds_ = dock_bounds; 1135ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch OnWindowResized(); 11365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) UpdateVisibilityState(); 1137a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) UpdateShelfBackground(BACKGROUND_CHANGE_ANIMATE); 1138ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch } 1139ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch} 1140ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch 114158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)void ShelfLayoutManager::OnLockStateEvent(LockStateObserver::EventType event) { 114258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) if (event == EVENT_LOCK_ANIMATION_STARTED) { 1143cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // Enter the screen locked state. 1144a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) state_.is_screen_locked = true; 114558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) } 114658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)} 114758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 1148a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochvoid ShelfLayoutManager::SessionStateChanged( 1149a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch SessionStateDelegate::SessionState state) { 1150a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch TargetBounds target_bounds; 1151a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch CalculateTargetBounds(state_, &target_bounds); 1152a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch UpdateBoundsAndOpacity(target_bounds, true, NULL); 1153a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch UpdateVisibilityState(); 1154a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch} 1155a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 11562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} // namespace ash 1157