| 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 | 86 |
| 87 tri_view->AddView(TriView::Container::START, icon_); | 87 tri_view->AddView(TriView::Container::START, icon_); |
| 88 tri_view->AddView(TriView::Container::CENTER, label_); | 88 tri_view->AddView(TriView::Container::CENTER, label_); |
| 89 tri_view->SetContainerVisible(TriView::Container::END, false); | 89 tri_view->SetContainerVisible(TriView::Container::END, false); |
| 90 | 90 |
| 91 Update(); | 91 Update(); |
| 92 | 92 |
| 93 SetInkDropMode(InkDropHostView::InkDropMode::ON); | 93 SetInkDropMode(InkDropHostView::InkDropMode::ON); |
| 94 | 94 |
| 95 SetVisible(IsMaximizeModeWindowManagerEnabled()); | 95 SetVisible(IsMaximizeModeWindowManagerEnabled()); |
| 96 WmShell::Get()->AddShellObserver(this); | 96 Shell::GetInstance()->AddShellObserver(this); |
| 97 if (IsMaximizeModeWindowManagerEnabled()) | 97 if (IsMaximizeModeWindowManagerEnabled()) |
| 98 Shell::GetInstance()->screen_orientation_controller()->AddObserver(this); | 98 Shell::GetInstance()->screen_orientation_controller()->AddObserver(this); |
| 99 } | 99 } |
| 100 | 100 |
| 101 RotationLockDefaultView::~RotationLockDefaultView() { | 101 RotationLockDefaultView::~RotationLockDefaultView() { |
| 102 StopObservingRotation(); | 102 StopObservingRotation(); |
| 103 WmShell::Get()->RemoveShellObserver(this); | 103 Shell::GetInstance()->RemoveShellObserver(this); |
| 104 } | 104 } |
| 105 | 105 |
| 106 void RotationLockDefaultView::Update() { | 106 void RotationLockDefaultView::Update() { |
| 107 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::DEFAULT_VIEW_LABEL); | 107 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::DEFAULT_VIEW_LABEL); |
| 108 icon_->SetImage(gfx::CreateVectorIcon(IsRotationLocked() | 108 icon_->SetImage(gfx::CreateVectorIcon(IsRotationLocked() |
| 109 ? kSystemMenuRotationLockLockedIcon | 109 ? kSystemMenuRotationLockLockedIcon |
| 110 : kSystemMenuRotationLockAutoIcon, | 110 : kSystemMenuRotationLockAutoIcon, |
| 111 kMenuIconSize, style.GetIconColor())); | 111 kMenuIconSize, style.GetIconColor())); |
| 112 | 112 |
| 113 base::string16 label = l10n_util::GetStringUTF16( | 113 base::string16 label = l10n_util::GetStringUTF16( |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 void RotationLockDefaultView::OnRotationLockChanged(bool rotation_locked) { | 153 void RotationLockDefaultView::OnRotationLockChanged(bool rotation_locked) { |
| 154 Update(); | 154 Update(); |
| 155 } | 155 } |
| 156 | 156 |
| 157 } // namespace tray | 157 } // namespace tray |
| 158 | 158 |
| 159 TrayRotationLock::TrayRotationLock(SystemTray* system_tray) | 159 TrayRotationLock::TrayRotationLock(SystemTray* system_tray) |
| 160 : TrayImageItem(system_tray, | 160 : TrayImageItem(system_tray, |
| 161 kSystemTrayRotationLockLockedIcon, | 161 kSystemTrayRotationLockLockedIcon, |
| 162 UMA_ROTATION_LOCK) { | 162 UMA_ROTATION_LOCK) { |
| 163 WmShell::Get()->AddShellObserver(this); | 163 Shell::GetInstance()->AddShellObserver(this); |
| 164 } | 164 } |
| 165 | 165 |
| 166 TrayRotationLock::~TrayRotationLock() { | 166 TrayRotationLock::~TrayRotationLock() { |
| 167 WmShell::Get()->RemoveShellObserver(this); | 167 Shell::GetInstance()->RemoveShellObserver(this); |
| 168 } | 168 } |
| 169 | 169 |
| 170 void TrayRotationLock::OnRotationLockChanged(bool rotation_locked) { | 170 void TrayRotationLock::OnRotationLockChanged(bool rotation_locked) { |
| 171 tray_view()->SetVisible(ShouldBeVisible()); | 171 tray_view()->SetVisible(ShouldBeVisible()); |
| 172 } | 172 } |
| 173 | 173 |
| 174 views::View* TrayRotationLock::CreateDefaultView(LoginStatus status) { | 174 views::View* TrayRotationLock::CreateDefaultView(LoginStatus status) { |
| 175 if (OnPrimaryDisplay()) | 175 if (OnPrimaryDisplay()) |
| 176 return new tray::RotationLockDefaultView(this); | 176 return new tray::RotationLockDefaultView(this); |
| 177 return nullptr; | 177 return nullptr; |
| 178 } | 178 } |
| 179 | 179 |
| 180 void TrayRotationLock::OnMaximizeModeStarted() { | 180 void TrayRotationLock::OnMaximizeModeStarted() { |
| 181 tray_view()->SetVisible(IsRotationLocked()); | 181 tray_view()->SetVisible(IsRotationLocked()); |
| 182 Shell::GetInstance()->screen_orientation_controller()->AddObserver(this); | 182 Shell::GetInstance()->screen_orientation_controller()->AddObserver(this); |
| 183 } | 183 } |
| 184 | 184 |
| 185 void TrayRotationLock::OnMaximizeModeEnded() { | 185 void TrayRotationLock::OnMaximizeModeEnded() { |
| 186 tray_view()->SetVisible(false); | 186 tray_view()->SetVisible(false); |
| 187 StopObservingRotation(); | 187 StopObservingRotation(); |
| 188 } | 188 } |
| 189 | 189 |
| 190 void TrayRotationLock::DestroyTrayView() { | 190 void TrayRotationLock::DestroyTrayView() { |
| 191 StopObservingRotation(); | 191 StopObservingRotation(); |
| 192 WmShell::Get()->RemoveShellObserver(this); | 192 Shell::GetInstance()->RemoveShellObserver(this); |
| 193 TrayImageItem::DestroyTrayView(); | 193 TrayImageItem::DestroyTrayView(); |
| 194 } | 194 } |
| 195 | 195 |
| 196 bool TrayRotationLock::GetInitialVisibility() { | 196 bool TrayRotationLock::GetInitialVisibility() { |
| 197 return ShouldBeVisible(); | 197 return ShouldBeVisible(); |
| 198 } | 198 } |
| 199 | 199 |
| 200 bool TrayRotationLock::ShouldBeVisible() { | 200 bool TrayRotationLock::ShouldBeVisible() { |
| 201 return OnPrimaryDisplay() && IsMaximizeModeWindowManagerEnabled() && | 201 return OnPrimaryDisplay() && IsMaximizeModeWindowManagerEnabled() && |
| 202 IsRotationLocked(); | 202 IsRotationLocked(); |
| 203 } | 203 } |
| 204 | 204 |
| 205 bool TrayRotationLock::OnPrimaryDisplay() const { | 205 bool TrayRotationLock::OnPrimaryDisplay() const { |
| 206 gfx::NativeView native_view = system_tray()->GetWidget()->GetNativeView(); | 206 gfx::NativeView native_view = system_tray()->GetWidget()->GetNativeView(); |
| 207 display::Display parent_display = | 207 display::Display parent_display = |
| 208 display::Screen::GetScreen()->GetDisplayNearestWindow(native_view); | 208 display::Screen::GetScreen()->GetDisplayNearestWindow(native_view); |
| 209 return parent_display.IsInternal(); | 209 return parent_display.IsInternal(); |
| 210 } | 210 } |
| 211 | 211 |
| 212 void TrayRotationLock::StopObservingRotation() { | 212 void TrayRotationLock::StopObservingRotation() { |
| 213 ScreenOrientationController* controller = | 213 ScreenOrientationController* controller = |
| 214 Shell::GetInstance()->screen_orientation_controller(); | 214 Shell::GetInstance()->screen_orientation_controller(); |
| 215 if (controller) | 215 if (controller) |
| 216 controller->RemoveObserver(this); | 216 controller->RemoveObserver(this); |
| 217 } | 217 } |
| 218 | 218 |
| 219 } // namespace ash | 219 } // namespace ash |
| OLD | NEW |