| 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/chromeos/rotation/tray_rotation_lock.h" | 5 #include "ash/system/chromeos/rotation/tray_rotation_lock.h" |
| 6 | 6 |
| 7 #include "ash/common/system/tray/actionable_view.h" | 7 #include "ash/common/system/tray/actionable_view.h" |
| 8 #include "ash/common/system/tray/system_tray.h" | 8 #include "ash/common/system/tray/system_tray.h" |
| 9 #include "ash/common/system/tray/tray_constants.h" | 9 #include "ash/common/system/tray/tray_constants.h" |
| 10 #include "ash/common/system/tray/tray_popup_item_style.h" | 10 #include "ash/common/system/tray/tray_popup_item_style.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 namespace ash { | 26 namespace ash { |
| 27 | 27 |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 30 bool IsMaximizeModeWindowManagerEnabled() { | 30 bool IsMaximizeModeWindowManagerEnabled() { |
| 31 return Shell::Get() | 31 return Shell::Get() |
| 32 ->maximize_mode_controller() | 32 ->maximize_mode_controller() |
| 33 ->IsMaximizeModeWindowManagerEnabled(); | 33 ->IsMaximizeModeWindowManagerEnabled(); |
| 34 } | 34 } |
| 35 | 35 |
| 36 bool IsRotationLocked() { | 36 bool IsUserRotationLocked() { |
| 37 return Shell::GetInstance() | 37 return Shell::GetInstance() |
| 38 ->screen_orientation_controller() | 38 ->screen_orientation_controller() |
| 39 ->rotation_locked(); | 39 ->user_rotation_locked(); |
| 40 } | 40 } |
| 41 | 41 |
| 42 } // namespace | 42 } // namespace |
| 43 | 43 |
| 44 namespace tray { | 44 namespace tray { |
| 45 | 45 |
| 46 class RotationLockDefaultView : public ActionableView, | 46 class RotationLockDefaultView : public ActionableView, |
| 47 public ShellObserver, | 47 public ShellObserver, |
| 48 public ScreenOrientationController::Observer { | 48 public ScreenOrientationController::Observer { |
| 49 public: | 49 public: |
| 50 explicit RotationLockDefaultView(SystemTrayItem* owner); | 50 explicit RotationLockDefaultView(SystemTrayItem* owner); |
| 51 ~RotationLockDefaultView() override; | 51 ~RotationLockDefaultView() override; |
| 52 | 52 |
| 53 private: | 53 private: |
| 54 // Updates icon and label according to current rotation lock status. | 54 // Updates icon and label according to current rotation lock status. |
| 55 void Update(); | 55 void Update(); |
| 56 | 56 |
| 57 // Stop observing rotation lock status. | 57 // Stop observing rotation lock status. |
| 58 void StopObservingRotation(); | 58 void StopObservingRotation(); |
| 59 | 59 |
| 60 // ActionableView: | 60 // ActionableView: |
| 61 void GetAccessibleNodeData(ui::AXNodeData* node_data) override; | 61 void GetAccessibleNodeData(ui::AXNodeData* node_data) override; |
| 62 bool PerformAction(const ui::Event& event) override; | 62 bool PerformAction(const ui::Event& event) override; |
| 63 | 63 |
| 64 // ShellObserver: | 64 // ShellObserver: |
| 65 void OnMaximizeModeStarted() override; | 65 void OnMaximizeModeStarted() override; |
| 66 void OnMaximizeModeEnded() override; | 66 void OnMaximizeModeEnded() override; |
| 67 | 67 |
| 68 // ScreenOrientationController::Obsever: | 68 // ScreenOrientationController::Obsever: |
| 69 void OnRotationLockChanged(bool rotation_locked) override; | 69 void OnUserRotationLockChanged() override; |
| 70 | 70 |
| 71 views::ImageView* icon_; | 71 views::ImageView* icon_; |
| 72 views::Label* label_; | 72 views::Label* label_; |
| 73 | 73 |
| 74 DISALLOW_COPY_AND_ASSIGN(RotationLockDefaultView); | 74 DISALLOW_COPY_AND_ASSIGN(RotationLockDefaultView); |
| 75 }; | 75 }; |
| 76 | 76 |
| 77 RotationLockDefaultView::RotationLockDefaultView(SystemTrayItem* owner) | 77 RotationLockDefaultView::RotationLockDefaultView(SystemTrayItem* owner) |
| 78 : ActionableView(owner, TrayPopupInkDropStyle::FILL_BOUNDS), | 78 : ActionableView(owner, TrayPopupInkDropStyle::FILL_BOUNDS), |
| 79 icon_(TrayPopupUtils::CreateMainImageView()), | 79 icon_(TrayPopupUtils::CreateMainImageView()), |
| (...skipping 17 matching lines...) Expand all Loading... |
| 97 Shell::GetInstance()->screen_orientation_controller()->AddObserver(this); | 97 Shell::GetInstance()->screen_orientation_controller()->AddObserver(this); |
| 98 } | 98 } |
| 99 | 99 |
| 100 RotationLockDefaultView::~RotationLockDefaultView() { | 100 RotationLockDefaultView::~RotationLockDefaultView() { |
| 101 StopObservingRotation(); | 101 StopObservingRotation(); |
| 102 Shell::GetInstance()->RemoveShellObserver(this); | 102 Shell::GetInstance()->RemoveShellObserver(this); |
| 103 } | 103 } |
| 104 | 104 |
| 105 void RotationLockDefaultView::Update() { | 105 void RotationLockDefaultView::Update() { |
| 106 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::DEFAULT_VIEW_LABEL); | 106 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::DEFAULT_VIEW_LABEL); |
| 107 icon_->SetImage(gfx::CreateVectorIcon(IsRotationLocked() | 107 icon_->SetImage(gfx::CreateVectorIcon(IsUserRotationLocked() |
| 108 ? kSystemMenuRotationLockLockedIcon | 108 ? kSystemMenuRotationLockLockedIcon |
| 109 : kSystemMenuRotationLockAutoIcon, | 109 : kSystemMenuRotationLockAutoIcon, |
| 110 kMenuIconSize, style.GetIconColor())); | 110 kMenuIconSize, style.GetIconColor())); |
| 111 | 111 |
| 112 base::string16 label = l10n_util::GetStringUTF16( | 112 base::string16 label = l10n_util::GetStringUTF16( |
| 113 IsRotationLocked() ? IDS_ASH_STATUS_TRAY_ROTATION_LOCK_LOCKED | 113 IsUserRotationLocked() ? IDS_ASH_STATUS_TRAY_ROTATION_LOCK_LOCKED |
| 114 : IDS_ASH_STATUS_TRAY_ROTATION_LOCK_AUTO); | 114 : IDS_ASH_STATUS_TRAY_ROTATION_LOCK_AUTO); |
| 115 label_->SetText(label); | 115 label_->SetText(label); |
| 116 style.SetupLabel(label_); | 116 style.SetupLabel(label_); |
| 117 | 117 |
| 118 Layout(); | 118 Layout(); |
| 119 SchedulePaint(); | 119 SchedulePaint(); |
| 120 } | 120 } |
| 121 | 121 |
| 122 void RotationLockDefaultView::StopObservingRotation() { | 122 void RotationLockDefaultView::StopObservingRotation() { |
| 123 ScreenOrientationController* controller = | 123 ScreenOrientationController* controller = |
| 124 Shell::GetInstance()->screen_orientation_controller(); | 124 Shell::GetInstance()->screen_orientation_controller(); |
| 125 if (controller) | 125 if (controller) |
| 126 controller->RemoveObserver(this); | 126 controller->RemoveObserver(this); |
| 127 } | 127 } |
| 128 | 128 |
| 129 void RotationLockDefaultView::GetAccessibleNodeData(ui::AXNodeData* node_data) { | 129 void RotationLockDefaultView::GetAccessibleNodeData(ui::AXNodeData* node_data) { |
| 130 ActionableView::GetAccessibleNodeData(node_data); | 130 ActionableView::GetAccessibleNodeData(node_data); |
| 131 if (!label_->text().empty()) | 131 if (!label_->text().empty()) |
| 132 node_data->SetName(label_->text()); | 132 node_data->SetName(label_->text()); |
| 133 } | 133 } |
| 134 | 134 |
| 135 bool RotationLockDefaultView::PerformAction(const ui::Event& event) { | 135 bool RotationLockDefaultView::PerformAction(const ui::Event& event) { |
| 136 Shell::GetInstance()->screen_orientation_controller()->SetRotationLocked( | 136 Shell::GetInstance() |
| 137 !IsRotationLocked()); | 137 ->screen_orientation_controller() |
| 138 ->ToggleUserRotationLock(); |
| 138 return true; | 139 return true; |
| 139 } | 140 } |
| 140 | 141 |
| 141 void RotationLockDefaultView::OnMaximizeModeStarted() { | 142 void RotationLockDefaultView::OnMaximizeModeStarted() { |
| 142 Update(); | 143 Update(); |
| 143 SetVisible(true); | 144 SetVisible(true); |
| 144 Shell::GetInstance()->screen_orientation_controller()->AddObserver(this); | 145 Shell::GetInstance()->screen_orientation_controller()->AddObserver(this); |
| 145 } | 146 } |
| 146 | 147 |
| 147 void RotationLockDefaultView::OnMaximizeModeEnded() { | 148 void RotationLockDefaultView::OnMaximizeModeEnded() { |
| 148 SetVisible(false); | 149 SetVisible(false); |
| 149 StopObservingRotation(); | 150 StopObservingRotation(); |
| 150 } | 151 } |
| 151 | 152 |
| 152 void RotationLockDefaultView::OnRotationLockChanged(bool rotation_locked) { | 153 void RotationLockDefaultView::OnUserRotationLockChanged() { |
| 153 Update(); | 154 Update(); |
| 154 } | 155 } |
| 155 | 156 |
| 156 } // namespace tray | 157 } // namespace tray |
| 157 | 158 |
| 158 TrayRotationLock::TrayRotationLock(SystemTray* system_tray) | 159 TrayRotationLock::TrayRotationLock(SystemTray* system_tray) |
| 159 : TrayImageItem(system_tray, | 160 : TrayImageItem(system_tray, |
| 160 kSystemTrayRotationLockLockedIcon, | 161 kSystemTrayRotationLockLockedIcon, |
| 161 UMA_ROTATION_LOCK) { | 162 UMA_ROTATION_LOCK) { |
| 162 Shell::GetInstance()->AddShellObserver(this); | 163 Shell::GetInstance()->AddShellObserver(this); |
| 163 } | 164 } |
| 164 | 165 |
| 165 TrayRotationLock::~TrayRotationLock() { | 166 TrayRotationLock::~TrayRotationLock() { |
| 166 Shell::GetInstance()->RemoveShellObserver(this); | 167 Shell::GetInstance()->RemoveShellObserver(this); |
| 167 } | 168 } |
| 168 | 169 |
| 169 void TrayRotationLock::OnRotationLockChanged(bool rotation_locked) { | 170 void TrayRotationLock::OnUserRotationLockChanged() { |
| 170 tray_view()->SetVisible(ShouldBeVisible()); | 171 tray_view()->SetVisible(ShouldBeVisible()); |
| 171 } | 172 } |
| 172 | 173 |
| 173 views::View* TrayRotationLock::CreateDefaultView(LoginStatus status) { | 174 views::View* TrayRotationLock::CreateDefaultView(LoginStatus status) { |
| 174 if (OnPrimaryDisplay()) | 175 if (OnPrimaryDisplay()) |
| 175 return new tray::RotationLockDefaultView(this); | 176 return new tray::RotationLockDefaultView(this); |
| 176 return nullptr; | 177 return nullptr; |
| 177 } | 178 } |
| 178 | 179 |
| 179 void TrayRotationLock::OnMaximizeModeStarted() { | 180 void TrayRotationLock::OnMaximizeModeStarted() { |
| 180 tray_view()->SetVisible(IsRotationLocked()); | 181 tray_view()->SetVisible(IsUserRotationLocked()); |
| 181 Shell::GetInstance()->screen_orientation_controller()->AddObserver(this); | 182 Shell::GetInstance()->screen_orientation_controller()->AddObserver(this); |
| 182 } | 183 } |
| 183 | 184 |
| 184 void TrayRotationLock::OnMaximizeModeEnded() { | 185 void TrayRotationLock::OnMaximizeModeEnded() { |
| 185 tray_view()->SetVisible(false); | 186 tray_view()->SetVisible(false); |
| 186 StopObservingRotation(); | 187 StopObservingRotation(); |
| 187 } | 188 } |
| 188 | 189 |
| 189 void TrayRotationLock::DestroyTrayView() { | 190 void TrayRotationLock::DestroyTrayView() { |
| 190 StopObservingRotation(); | 191 StopObservingRotation(); |
| 191 Shell::GetInstance()->RemoveShellObserver(this); | 192 Shell::GetInstance()->RemoveShellObserver(this); |
| 192 TrayImageItem::DestroyTrayView(); | 193 TrayImageItem::DestroyTrayView(); |
| 193 } | 194 } |
| 194 | 195 |
| 195 bool TrayRotationLock::GetInitialVisibility() { | 196 bool TrayRotationLock::GetInitialVisibility() { |
| 196 return ShouldBeVisible(); | 197 return ShouldBeVisible(); |
| 197 } | 198 } |
| 198 | 199 |
| 199 bool TrayRotationLock::ShouldBeVisible() { | 200 bool TrayRotationLock::ShouldBeVisible() { |
| 200 return OnPrimaryDisplay() && IsMaximizeModeWindowManagerEnabled() && | 201 return OnPrimaryDisplay() && IsMaximizeModeWindowManagerEnabled() && |
| 201 IsRotationLocked(); | 202 IsUserRotationLocked(); |
| 202 } | 203 } |
| 203 | 204 |
| 204 bool TrayRotationLock::OnPrimaryDisplay() const { | 205 bool TrayRotationLock::OnPrimaryDisplay() const { |
| 205 gfx::NativeView native_view = system_tray()->GetWidget()->GetNativeView(); | 206 gfx::NativeView native_view = system_tray()->GetWidget()->GetNativeView(); |
| 206 display::Display parent_display = | 207 display::Display parent_display = |
| 207 display::Screen::GetScreen()->GetDisplayNearestWindow(native_view); | 208 display::Screen::GetScreen()->GetDisplayNearestWindow(native_view); |
| 208 return parent_display.IsInternal(); | 209 return parent_display.IsInternal(); |
| 209 } | 210 } |
| 210 | 211 |
| 211 void TrayRotationLock::StopObservingRotation() { | 212 void TrayRotationLock::StopObservingRotation() { |
| 212 ScreenOrientationController* controller = | 213 ScreenOrientationController* controller = |
| 213 Shell::GetInstance()->screen_orientation_controller(); | 214 Shell::GetInstance()->screen_orientation_controller(); |
| 214 if (controller) | 215 if (controller) |
| 215 controller->RemoveObserver(this); | 216 controller->RemoveObserver(this); |
| 216 } | 217 } |
| 217 | 218 |
| 218 } // namespace ash | 219 } // namespace ash |
| OLD | NEW |