| 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/common/system/web_notification/ash_popup_alignment_delegate.h" |
| 6 | 6 |
| 7 #include "ash/common/shelf/shelf_constants.h" | 7 #include "ash/common/shelf/shelf_constants.h" |
| 8 #include "ash/common/shelf/shelf_types.h" | 8 #include "ash/common/shelf/shelf_types.h" |
| 9 #include "ash/common/shelf/wm_shelf.h" | 9 #include "ash/common/shelf/wm_shelf.h" |
| 10 #include "ash/common/shell_window_ids.h" | 10 #include "ash/common/shell_window_ids.h" |
| 11 #include "ash/common/wm_root_window_controller.h" | 11 #include "ash/common/wm_root_window_controller.h" |
| 12 #include "ash/common/wm_shell.h" | 12 #include "ash/common/wm_shell.h" |
| 13 #include "ash/common/wm_window.h" | 13 #include "ash/common/wm_window.h" |
| 14 #include "base/i18n/rtl.h" | 14 #include "base/i18n/rtl.h" |
| 15 #include "ui/display/display.h" | 15 #include "ui/display/display.h" |
| 16 #include "ui/display/screen.h" | 16 #include "ui/display/screen.h" |
| 17 #include "ui/gfx/geometry/rect.h" | 17 #include "ui/gfx/geometry/rect.h" |
| 18 #include "ui/message_center/message_center_style.h" | 18 #include "ui/message_center/message_center_style.h" |
| 19 #include "ui/message_center/views/message_popup_collection.h" | 19 #include "ui/message_center/views/message_popup_collection.h" |
| 20 | 20 |
| 21 namespace ash { | 21 namespace ash { |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 const int kToastMarginX = 3; | 25 const int kToastMarginX = 3; |
| 26 | 26 |
| 27 // If there should be no margin for the first item, this value needs to be | 27 // If there should be no margin for the first item, this value needs to be |
| 28 // substracted to flush the message to the shelf (the width of the border + | 28 // substracted to flush the message to the shelf (the width of the border + |
| 29 // shadow). | 29 // shadow). |
| 30 const int kNoToastMarginBorderAndShadowOffset = 2; | 30 const int kNoToastMarginBorderAndShadowOffset = 2; |
| 31 | 31 |
| 32 } // namespace | 32 } // namespace |
| 33 | 33 |
| 34 AshPopupAlignmentDelegate::AshPopupAlignmentDelegate(WmShelf* shelf) | 34 AshPopupAlignmentDelegate::AshPopupAlignmentDelegate(WmShelf* shelf) |
| 35 : screen_(NULL), shelf_(shelf), system_tray_height_(0) { | 35 : screen_(NULL), shelf_(shelf), tray_bubble_height_(0) { |
| 36 shelf_->AddObserver(this); | 36 shelf_->AddObserver(this); |
| 37 } | 37 } |
| 38 | 38 |
| 39 AshPopupAlignmentDelegate::~AshPopupAlignmentDelegate() { | 39 AshPopupAlignmentDelegate::~AshPopupAlignmentDelegate() { |
| 40 if (screen_) | 40 if (screen_) |
| 41 screen_->RemoveObserver(this); | 41 screen_->RemoveObserver(this); |
| 42 WmShell::Get()->RemoveShellObserver(this); | 42 WmShell::Get()->RemoveShellObserver(this); |
| 43 shelf_->RemoveObserver(this); | 43 shelf_->RemoveObserver(this); |
| 44 } | 44 } |
| 45 | 45 |
| 46 void AshPopupAlignmentDelegate::StartObserving( | 46 void AshPopupAlignmentDelegate::StartObserving( |
| 47 display::Screen* screen, | 47 display::Screen* screen, |
| 48 const display::Display& display) { | 48 const display::Display& display) { |
| 49 screen_ = screen; | 49 screen_ = screen; |
| 50 work_area_ = display.work_area(); | 50 work_area_ = display.work_area(); |
| 51 screen->AddObserver(this); | 51 screen->AddObserver(this); |
| 52 WmShell::Get()->AddShellObserver(this); | 52 WmShell::Get()->AddShellObserver(this); |
| 53 if (system_tray_height_ > 0) | 53 if (tray_bubble_height_ > 0) |
| 54 UpdateWorkArea(); | 54 UpdateWorkArea(); |
| 55 } | 55 } |
| 56 | 56 |
| 57 void AshPopupAlignmentDelegate::SetSystemTrayHeight(int height) { | 57 void AshPopupAlignmentDelegate::SetTrayBubbleHeight(int height) { |
| 58 system_tray_height_ = height; | 58 tray_bubble_height_ = height; |
| 59 | 59 |
| 60 // If the shelf is shown during auto-hide state, the distance from the edge | 60 // If the shelf is shown during auto-hide state, the distance from the edge |
| 61 // should be reduced by the height of shelf's shown height. | 61 // should be reduced by the height of shelf's shown height. |
| 62 if (shelf_->GetVisibilityState() == SHELF_AUTO_HIDE && | 62 if (shelf_->GetVisibilityState() == SHELF_AUTO_HIDE && |
| 63 shelf_->GetAutoHideState() == SHELF_AUTO_HIDE_SHOWN) { | 63 shelf_->GetAutoHideState() == SHELF_AUTO_HIDE_SHOWN) { |
| 64 system_tray_height_ -= GetShelfConstant(SHELF_SIZE) - | 64 tray_bubble_height_ -= GetShelfConstant(SHELF_SIZE) - |
| 65 GetShelfConstant(SHELF_INSETS_FOR_AUTO_HIDE); | 65 GetShelfConstant(SHELF_INSETS_FOR_AUTO_HIDE); |
| 66 } | 66 } |
| 67 | 67 |
| 68 if (system_tray_height_ > 0) | 68 if (tray_bubble_height_ > 0) |
| 69 system_tray_height_ += message_center::kMarginBetweenItems; | 69 tray_bubble_height_ += message_center::kMarginBetweenItems; |
| 70 else | 70 else |
| 71 system_tray_height_ = 0; | 71 tray_bubble_height_ = 0; |
| 72 | 72 |
| 73 DoUpdateIfPossible(); | 73 DoUpdateIfPossible(); |
| 74 } | 74 } |
| 75 | 75 |
| 76 int AshPopupAlignmentDelegate::GetToastOriginX( | 76 int AshPopupAlignmentDelegate::GetToastOriginX( |
| 77 const gfx::Rect& toast_bounds) const { | 77 const gfx::Rect& toast_bounds) const { |
| 78 // In Ash, RTL UI language mirrors the whole ash layout, so the toast | 78 // In Ash, RTL UI language mirrors the whole ash layout, so the toast |
| 79 // widgets should be at the bottom-left instead of bottom right. | 79 // widgets should be at the bottom-left instead of bottom right. |
| 80 if (base::i18n::IsRTL()) | 80 if (base::i18n::IsRTL()) |
| 81 return work_area_.x() + kToastMarginX; | 81 return work_area_.x() + kToastMarginX; |
| 82 | 82 |
| 83 if (IsFromLeft()) | 83 if (IsFromLeft()) |
| 84 return work_area_.x() + kToastMarginX; | 84 return work_area_.x() + kToastMarginX; |
| 85 return work_area_.right() - kToastMarginX - toast_bounds.width(); | 85 return work_area_.right() - kToastMarginX - toast_bounds.width(); |
| 86 } | 86 } |
| 87 | 87 |
| 88 int AshPopupAlignmentDelegate::GetBaseLine() const { | 88 int AshPopupAlignmentDelegate::GetBaseLine() const { |
| 89 return work_area_.bottom() - kNoToastMarginBorderAndShadowOffset - | 89 return work_area_.bottom() - kNoToastMarginBorderAndShadowOffset - |
| 90 system_tray_height_; | 90 tray_bubble_height_; |
| 91 } | 91 } |
| 92 | 92 |
| 93 int AshPopupAlignmentDelegate::GetWorkAreaBottom() const { | 93 int AshPopupAlignmentDelegate::GetWorkAreaBottom() const { |
| 94 return work_area_.bottom() - system_tray_height_; | 94 return work_area_.bottom() - tray_bubble_height_; |
| 95 } | 95 } |
| 96 | 96 |
| 97 bool AshPopupAlignmentDelegate::IsTopDown() const { | 97 bool AshPopupAlignmentDelegate::IsTopDown() const { |
| 98 return false; | 98 return false; |
| 99 } | 99 } |
| 100 | 100 |
| 101 bool AshPopupAlignmentDelegate::IsFromLeft() const { | 101 bool AshPopupAlignmentDelegate::IsFromLeft() const { |
| 102 return GetAlignment() == SHELF_ALIGNMENT_LEFT; | 102 return GetAlignment() == SHELF_ALIGNMENT_LEFT; |
| 103 } | 103 } |
| 104 | 104 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 const display::Display& old_display) {} | 160 const display::Display& old_display) {} |
| 161 | 161 |
| 162 void AshPopupAlignmentDelegate::OnDisplayMetricsChanged( | 162 void AshPopupAlignmentDelegate::OnDisplayMetricsChanged( |
| 163 const display::Display& display, | 163 const display::Display& display, |
| 164 uint32_t metrics) { | 164 uint32_t metrics) { |
| 165 if (GetCurrentDisplay().id() == display.id()) | 165 if (GetCurrentDisplay().id() == display.id()) |
| 166 UpdateWorkArea(); | 166 UpdateWorkArea(); |
| 167 } | 167 } |
| 168 | 168 |
| 169 } // namespace ash | 169 } // namespace ash |
| OLD | NEW |