| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/system/web_notification/ash_popup_alignment_delegate.h" | 5 #include "ash/system/web_notification/ash_popup_alignment_delegate.h" |
| 6 | 6 |
| 7 #include "ash/display/window_tree_host_manager.h" | 7 #include "ash/display/window_tree_host_manager.h" |
| 8 #include "ash/screen_util.h" | 8 #include "ash/screen_util.h" |
| 9 #include "ash/shelf/shelf_constants.h" | 9 #include "ash/shelf/shelf_constants.h" |
| 10 #include "ash/shelf/shelf_layout_manager.h" | 10 #include "ash/shelf/shelf_layout_manager.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 | 25 |
| 26 const int kToastMarginX = 3; | 26 const int kToastMarginX = 3; |
| 27 | 27 |
| 28 // If there should be no margin for the first item, this value needs to be | 28 // If there should be no margin for the first item, this value needs to be |
| 29 // substracted to flush the message to the shelf (the width of the border + | 29 // substracted to flush the message to the shelf (the width of the border + |
| 30 // shadow). | 30 // shadow). |
| 31 const int kNoToastMarginBorderAndShadowOffset = 2; | 31 const int kNoToastMarginBorderAndShadowOffset = 2; |
| 32 | 32 |
| 33 } | 33 } |
| 34 | 34 |
| 35 AshPopupAlignmentDelegate::AshPopupAlignmentDelegate() | 35 AshPopupAlignmentDelegate::AshPopupAlignmentDelegate(ShelfLayoutManager* shelf) |
| 36 : screen_(NULL), root_window_(NULL), shelf_(NULL), system_tray_height_(0) { | 36 : screen_(NULL), root_window_(NULL), shelf_(shelf), system_tray_height_(0) { |
| 37 shelf_->AddObserver(this); |
| 37 } | 38 } |
| 38 | 39 |
| 39 AshPopupAlignmentDelegate::~AshPopupAlignmentDelegate() { | 40 AshPopupAlignmentDelegate::~AshPopupAlignmentDelegate() { |
| 40 if (screen_) | 41 if (screen_) |
| 41 screen_->RemoveObserver(this); | 42 screen_->RemoveObserver(this); |
| 42 Shell::GetInstance()->RemoveShellObserver(this); | 43 Shell::GetInstance()->RemoveShellObserver(this); |
| 43 if (shelf_) | 44 shelf_->RemoveObserver(this); |
| 44 shelf_->RemoveObserver(this); | |
| 45 } | 45 } |
| 46 | 46 |
| 47 void AshPopupAlignmentDelegate::StartObserving(gfx::Screen* screen, | 47 void AshPopupAlignmentDelegate::StartObserving(gfx::Screen* screen, |
| 48 const gfx::Display& display) { | 48 const gfx::Display& display) { |
| 49 screen_ = screen; | 49 screen_ = screen; |
| 50 work_area_ = display.work_area(); | 50 work_area_ = display.work_area(); |
| 51 root_window_ = ash::Shell::GetInstance() | 51 root_window_ = ash::Shell::GetInstance() |
| 52 ->window_tree_host_manager() | 52 ->window_tree_host_manager() |
| 53 ->GetRootWindowForDisplayId(display.id()); | 53 ->GetRootWindowForDisplayId(display.id()); |
| 54 UpdateShelf(); | |
| 55 screen->AddObserver(this); | 54 screen->AddObserver(this); |
| 56 Shell::GetInstance()->AddShellObserver(this); | 55 Shell::GetInstance()->AddShellObserver(this); |
| 57 if (system_tray_height_ > 0) | 56 if (system_tray_height_ > 0) |
| 58 UpdateWorkArea(); | 57 UpdateWorkArea(); |
| 59 } | 58 } |
| 60 | 59 |
| 61 void AshPopupAlignmentDelegate::SetSystemTrayHeight(int height) { | 60 void AshPopupAlignmentDelegate::SetSystemTrayHeight(int height) { |
| 62 system_tray_height_ = height; | 61 system_tray_height_ = height; |
| 63 | 62 |
| 64 // If the shelf is shown during auto-hide state, the distance from the edge | 63 // If the shelf is shown during auto-hide state, the distance from the edge |
| 65 // should be reduced by the height of shelf's shown height. | 64 // should be reduced by the height of shelf's shown height. |
| 66 if (shelf_ && shelf_->visibility_state() == SHELF_AUTO_HIDE && | 65 if (shelf_->visibility_state() == SHELF_AUTO_HIDE && |
| 67 shelf_->auto_hide_state() == SHELF_AUTO_HIDE_SHOWN) { | 66 shelf_->auto_hide_state() == SHELF_AUTO_HIDE_SHOWN) { |
| 68 system_tray_height_ -= kShelfSize - ShelfLayoutManager::kAutoHideSize; | 67 system_tray_height_ -= kShelfSize - ShelfLayoutManager::kAutoHideSize; |
| 69 } | 68 } |
| 70 | 69 |
| 71 if (system_tray_height_ > 0) | 70 if (system_tray_height_ > 0) |
| 72 system_tray_height_ += message_center::kMarginBetweenItems; | 71 system_tray_height_ += message_center::kMarginBetweenItems; |
| 73 else | 72 else |
| 74 system_tray_height_ = 0; | 73 system_tray_height_ = 0; |
| 75 | 74 |
| 76 if (!shelf_) | |
| 77 return; | |
| 78 | |
| 79 DoUpdateIfPossible(); | 75 DoUpdateIfPossible(); |
| 80 } | 76 } |
| 81 | 77 |
| 82 int AshPopupAlignmentDelegate::GetToastOriginX( | 78 int AshPopupAlignmentDelegate::GetToastOriginX( |
| 83 const gfx::Rect& toast_bounds) const { | 79 const gfx::Rect& toast_bounds) const { |
| 84 // In Ash, RTL UI language mirrors the whole ash layout, so the toast | 80 // In Ash, RTL UI language mirrors the whole ash layout, so the toast |
| 85 // widgets should be at the bottom-left instead of bottom right. | 81 // widgets should be at the bottom-left instead of bottom right. |
| 86 if (base::i18n::IsRTL()) | 82 if (base::i18n::IsRTL()) |
| 87 return work_area_.x() + kToastMarginX; | 83 return work_area_.x() + kToastMarginX; |
| 88 | 84 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 110 bool AshPopupAlignmentDelegate::IsFromLeft() const { | 106 bool AshPopupAlignmentDelegate::IsFromLeft() const { |
| 111 return GetAlignment() == SHELF_ALIGNMENT_LEFT; | 107 return GetAlignment() == SHELF_ALIGNMENT_LEFT; |
| 112 } | 108 } |
| 113 | 109 |
| 114 void AshPopupAlignmentDelegate::RecomputeAlignment( | 110 void AshPopupAlignmentDelegate::RecomputeAlignment( |
| 115 const gfx::Display& display) { | 111 const gfx::Display& display) { |
| 116 // Nothing needs to be done. | 112 // Nothing needs to be done. |
| 117 } | 113 } |
| 118 | 114 |
| 119 ShelfAlignment AshPopupAlignmentDelegate::GetAlignment() const { | 115 ShelfAlignment AshPopupAlignmentDelegate::GetAlignment() const { |
| 120 return shelf_ ? shelf_->GetAlignment() : SHELF_ALIGNMENT_BOTTOM; | 116 return shelf_->GetAlignment(); |
| 121 } | |
| 122 | |
| 123 void AshPopupAlignmentDelegate::UpdateShelf() { | |
| 124 if (shelf_) | |
| 125 return; | |
| 126 | |
| 127 shelf_ = ShelfLayoutManager::ForShelf(root_window_); | |
| 128 if (shelf_) | |
| 129 shelf_->AddObserver(this); | |
| 130 } | 117 } |
| 131 | 118 |
| 132 gfx::Display AshPopupAlignmentDelegate::GetCurrentDisplay() const { | 119 gfx::Display AshPopupAlignmentDelegate::GetCurrentDisplay() const { |
| 133 return gfx::Screen::GetScreen()->GetDisplayNearestWindow( | 120 return gfx::Screen::GetScreen()->GetDisplayNearestWindow( |
| 134 shelf_->shelf_widget()->GetNativeView()); | 121 shelf_->shelf_widget()->GetNativeView()); |
| 135 } | 122 } |
| 136 | 123 |
| 137 void AshPopupAlignmentDelegate::UpdateWorkArea() { | 124 void AshPopupAlignmentDelegate::UpdateWorkArea() { |
| 138 work_area_ = shelf_->user_work_area_bounds(); | 125 work_area_ = shelf_->user_work_area_bounds(); |
| 139 DoUpdateIfPossible(); | 126 DoUpdateIfPossible(); |
| 140 } | 127 } |
| 141 | 128 |
| 142 void AshPopupAlignmentDelegate::OnDisplayWorkAreaInsetsChanged() { | 129 void AshPopupAlignmentDelegate::OnDisplayWorkAreaInsetsChanged() { |
| 143 UpdateShelf(); | |
| 144 UpdateWorkArea(); | 130 UpdateWorkArea(); |
| 145 } | 131 } |
| 146 | 132 |
| 147 void AshPopupAlignmentDelegate::WillChangeVisibilityState( | 133 void AshPopupAlignmentDelegate::WillChangeVisibilityState( |
| 148 ShelfVisibilityState new_state) { | 134 ShelfVisibilityState new_state) { |
| 149 UpdateWorkArea(); | 135 UpdateWorkArea(); |
| 150 } | 136 } |
| 151 | 137 |
| 152 void AshPopupAlignmentDelegate::OnAutoHideStateChanged( | 138 void AshPopupAlignmentDelegate::OnAutoHideStateChanged( |
| 153 ShelfAutoHideState new_state) { | 139 ShelfAutoHideState new_state) { |
| 154 UpdateWorkArea(); | 140 UpdateWorkArea(); |
| 155 } | 141 } |
| 156 | 142 |
| 157 void AshPopupAlignmentDelegate::OnDisplayAdded( | 143 void AshPopupAlignmentDelegate::OnDisplayAdded( |
| 158 const gfx::Display& new_display) { | 144 const gfx::Display& new_display) { |
| 159 } | 145 } |
| 160 | 146 |
| 161 void AshPopupAlignmentDelegate::OnDisplayRemoved( | 147 void AshPopupAlignmentDelegate::OnDisplayRemoved( |
| 162 const gfx::Display& old_display) { | 148 const gfx::Display& old_display) { |
| 163 } | 149 } |
| 164 | 150 |
| 165 void AshPopupAlignmentDelegate::OnDisplayMetricsChanged( | 151 void AshPopupAlignmentDelegate::OnDisplayMetricsChanged( |
| 166 const gfx::Display& display, | 152 const gfx::Display& display, |
| 167 uint32_t metrics) { | 153 uint32_t metrics) { |
| 168 UpdateShelf(); | 154 if (GetCurrentDisplay().id() == display.id()) |
| 169 if (shelf_ && GetCurrentDisplay().id() == display.id()) | |
| 170 UpdateWorkArea(); | 155 UpdateWorkArea(); |
| 171 } | 156 } |
| 172 | 157 |
| 173 } // namespace ash | 158 } // namespace ash |
| OLD | NEW |