OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/palette/palette_tray.h" | 5 #include "ash/system/palette/palette_tray.h" |
6 | 6 |
7 #include "ash/accelerators/accelerator_controller.h" | 7 #include "ash/accelerators/accelerator_controller.h" |
8 #include "ash/accessibility_delegate.h" | 8 #include "ash/accessibility_delegate.h" |
9 #include "ash/resources/vector_icons/vector_icons.h" | 9 #include "ash/resources/vector_icons/vector_icons.h" |
10 #include "ash/root_window_controller.h" | 10 #include "ash/root_window_controller.h" |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 } | 156 } |
157 | 157 |
158 PaletteTray::~PaletteTray() { | 158 PaletteTray::~PaletteTray() { |
159 if (bubble_) | 159 if (bubble_) |
160 bubble_->bubble_view()->ResetDelegate(); | 160 bubble_->bubble_view()->ResetDelegate(); |
161 | 161 |
162 ui::InputDeviceManager::GetInstance()->RemoveObserver(this); | 162 ui::InputDeviceManager::GetInstance()->RemoveObserver(this); |
163 Shell::Get()->RemoveShellObserver(this); | 163 Shell::Get()->RemoveShellObserver(this); |
164 } | 164 } |
165 | 165 |
166 bool PaletteTray::PerformAction(const ui::Event& event) { | |
167 if (bubble_) { | |
168 if (num_actions_in_bubble_ == 0) | |
169 RecordPaletteOptionsUsage(PaletteTrayOptions::PALETTE_CLOSED_NO_ACTION); | |
170 HidePalette(); | |
171 return true; | |
172 } | |
173 | |
174 return ShowPalette(); | |
175 } | |
176 | |
177 bool PaletteTray::ShowPalette() { | |
178 if (bubble_) | |
179 return false; | |
180 | |
181 DCHECK(tray_container()); | |
182 | |
183 views::TrayBubbleView::InitParams init_params; | |
184 init_params.delegate = this; | |
185 init_params.parent_window = GetBubbleWindowContainer(); | |
186 init_params.anchor_view = GetBubbleAnchor(); | |
187 init_params.anchor_alignment = GetAnchorAlignment(); | |
188 init_params.min_width = kPaletteWidth; | |
189 init_params.max_width = kPaletteWidth; | |
190 init_params.close_on_deactivate = true; | |
191 | |
192 // TODO(tdanderson): Refactor into common row layout code. | |
193 // TODO(tdanderson|jdufault): Add material design ripple effects to the menu | |
194 // rows. | |
195 | |
196 // Create and customize bubble view. | |
197 views::TrayBubbleView* bubble_view = new views::TrayBubbleView(init_params); | |
198 bubble_view->set_anchor_view_insets(GetBubbleAnchorInsets()); | |
199 bubble_view->set_margins( | |
200 gfx::Insets(kPalettePaddingOnTop, 0, kPalettePaddingOnBottom, 0)); | |
201 | |
202 // Add title. | |
203 auto* title_view = new TitleView(this); | |
204 title_view->SetBorder(views::CreateEmptyBorder( | |
205 gfx::Insets(0, kPaddingBetweenTitleAndLeftEdge, 0, 0))); | |
206 bubble_view->AddChildView(title_view); | |
207 | |
208 // Add horizontal separator. | |
209 views::Separator* separator = new views::Separator(); | |
210 separator->SetColor(kPaletteSeparatorColor); | |
211 separator->SetBorder(views::CreateEmptyBorder(gfx::Insets( | |
212 kPaddingBetweenTitleAndSeparator, 0, kMenuSeparatorVerticalPadding, 0))); | |
213 bubble_view->AddChildView(separator); | |
214 | |
215 // Add palette tools. | |
216 // TODO(tdanderson|jdufault): Use SystemMenuButton to get the material design | |
217 // ripples. | |
218 std::vector<PaletteToolView> views = palette_tool_manager_->CreateViews(); | |
219 for (const PaletteToolView& view : views) | |
220 bubble_view->AddChildView(view.view); | |
221 | |
222 // Show the bubble. | |
223 bubble_.reset(new ash::TrayBubbleWrapper(this, bubble_view)); | |
224 SetIsActive(true); | |
225 return true; | |
226 } | |
227 | |
228 bool PaletteTray::ContainsPointInScreen(const gfx::Point& point) { | 166 bool PaletteTray::ContainsPointInScreen(const gfx::Point& point) { |
229 if (icon_ && icon_->GetBoundsInScreen().Contains(point)) | 167 if (icon_ && icon_->GetBoundsInScreen().Contains(point)) |
230 return true; | 168 return true; |
231 | 169 |
232 return bubble_ && bubble_->bubble_view()->GetBoundsInScreen().Contains(point); | 170 return bubble_ && bubble_->bubble_view()->GetBoundsInScreen().Contains(point); |
233 } | 171 } |
234 | 172 |
235 void PaletteTray::OnSessionStateChanged(session_manager::SessionState state) { | 173 void PaletteTray::OnSessionStateChanged(session_manager::SessionState state) { |
236 UpdateIconVisibility(); | 174 UpdateIconVisibility(); |
237 } | 175 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 | 211 |
274 // Don't do anything if the palette should not be shown or if the user has | 212 // Don't do anything if the palette should not be shown or if the user has |
275 // disabled it all-together. | 213 // disabled it all-together. |
276 if (!IsInUserSession() || !palette_delegate->ShouldShowPalette()) | 214 if (!IsInUserSession() || !palette_delegate->ShouldShowPalette()) |
277 return; | 215 return; |
278 | 216 |
279 // Auto show/hide the palette if allowed by the user. | 217 // Auto show/hide the palette if allowed by the user. |
280 if (palette_delegate->ShouldAutoOpenPalette()) { | 218 if (palette_delegate->ShouldAutoOpenPalette()) { |
281 if (stylus_state == ui::StylusState::REMOVED && !bubble_) { | 219 if (stylus_state == ui::StylusState::REMOVED && !bubble_) { |
282 is_bubble_auto_opened_ = true; | 220 is_bubble_auto_opened_ = true; |
283 ShowPalette(); | 221 ShowBubble(); |
284 } else if (stylus_state == ui::StylusState::INSERTED && bubble_) { | 222 } else if (stylus_state == ui::StylusState::INSERTED && bubble_) { |
285 HidePalette(); | 223 HidePalette(); |
286 } | 224 } |
287 } | 225 } |
288 | 226 |
289 // Disable any active modes if the stylus has been inserted. | 227 // Disable any active modes if the stylus has been inserted. |
290 if (stylus_state == ui::StylusState::INSERTED) | 228 if (stylus_state == ui::StylusState::INSERTED) |
291 palette_tool_manager_->DisableActiveTool(PaletteGroup::MODE); | 229 palette_tool_manager_->DisableActiveTool(PaletteGroup::MODE); |
292 } | 230 } |
293 | 231 |
(...skipping 23 matching lines...) Expand all Loading... |
317 } | 255 } |
318 | 256 |
319 bool PaletteTray::ShouldEnableExtraKeyboardAccessibility() { | 257 bool PaletteTray::ShouldEnableExtraKeyboardAccessibility() { |
320 return Shell::Get()->accessibility_delegate()->IsSpokenFeedbackEnabled(); | 258 return Shell::Get()->accessibility_delegate()->IsSpokenFeedbackEnabled(); |
321 } | 259 } |
322 | 260 |
323 void PaletteTray::HideBubble(const views::TrayBubbleView* bubble_view) { | 261 void PaletteTray::HideBubble(const views::TrayBubbleView* bubble_view) { |
324 HideBubbleWithView(bubble_view); | 262 HideBubbleWithView(bubble_view); |
325 } | 263 } |
326 | 264 |
| 265 bool PaletteTray::ProcessGestureEventForBubble(ui::GestureEvent* event) { |
| 266 return drag_controller()->ProcessGestureEvent(event, this); |
| 267 } |
| 268 |
327 void PaletteTray::HidePalette() { | 269 void PaletteTray::HidePalette() { |
328 is_bubble_auto_opened_ = false; | 270 is_bubble_auto_opened_ = false; |
329 num_actions_in_bubble_ = 0; | 271 num_actions_in_bubble_ = 0; |
330 bubble_.reset(); | 272 bubble_.reset(); |
331 | 273 |
332 shelf()->UpdateAutoHideState(); | 274 shelf()->UpdateAutoHideState(); |
333 } | 275 } |
334 | 276 |
335 void PaletteTray::HidePaletteImmediately() { | 277 void PaletteTray::HidePaletteImmediately() { |
336 if (bubble_) | 278 if (bubble_) |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 // |delegate| can be null in tests. | 320 // |delegate| can be null in tests. |
379 if (!delegate) | 321 if (!delegate) |
380 return; | 322 return; |
381 | 323 |
382 // OnPaletteEnabledPrefChanged will get called with the initial pref value, | 324 // OnPaletteEnabledPrefChanged will get called with the initial pref value, |
383 // which will take care of showing the palette. | 325 // which will take care of showing the palette. |
384 palette_enabled_subscription_ = delegate->AddPaletteEnableListener(base::Bind( | 326 palette_enabled_subscription_ = delegate->AddPaletteEnableListener(base::Bind( |
385 &PaletteTray::OnPaletteEnabledPrefChanged, weak_factory_.GetWeakPtr())); | 327 &PaletteTray::OnPaletteEnabledPrefChanged, weak_factory_.GetWeakPtr())); |
386 } | 328 } |
387 | 329 |
| 330 bool PaletteTray::PerformAction(const ui::Event& event) { |
| 331 if (bubble_) { |
| 332 if (num_actions_in_bubble_ == 0) |
| 333 RecordPaletteOptionsUsage(PaletteTrayOptions::PALETTE_CLOSED_NO_ACTION); |
| 334 HidePalette(); |
| 335 return true; |
| 336 } |
| 337 |
| 338 ShowBubble(); |
| 339 return true; |
| 340 } |
| 341 |
| 342 void PaletteTray::CloseBubble() { |
| 343 HidePalette(); |
| 344 } |
| 345 |
| 346 void PaletteTray::ShowBubble() { |
| 347 if (bubble_) |
| 348 return; |
| 349 |
| 350 DCHECK(tray_container()); |
| 351 |
| 352 views::TrayBubbleView::InitParams init_params; |
| 353 init_params.delegate = this; |
| 354 init_params.parent_window = GetBubbleWindowContainer(); |
| 355 init_params.anchor_view = GetBubbleAnchor(); |
| 356 init_params.anchor_alignment = GetAnchorAlignment(); |
| 357 init_params.min_width = kPaletteWidth; |
| 358 init_params.max_width = kPaletteWidth; |
| 359 init_params.close_on_deactivate = true; |
| 360 |
| 361 // TODO(tdanderson): Refactor into common row layout code. |
| 362 // TODO(tdanderson|jdufault): Add material design ripple effects to the menu |
| 363 // rows. |
| 364 |
| 365 // Create and customize bubble view. |
| 366 views::TrayBubbleView* bubble_view = new views::TrayBubbleView(init_params); |
| 367 bubble_view->set_anchor_view_insets(GetBubbleAnchorInsets()); |
| 368 bubble_view->set_margins( |
| 369 gfx::Insets(kPalettePaddingOnTop, 0, kPalettePaddingOnBottom, 0)); |
| 370 |
| 371 // Add title. |
| 372 auto* title_view = new TitleView(this); |
| 373 title_view->SetBorder(views::CreateEmptyBorder( |
| 374 gfx::Insets(0, kPaddingBetweenTitleAndLeftEdge, 0, 0))); |
| 375 bubble_view->AddChildView(title_view); |
| 376 |
| 377 // Add horizontal separator. |
| 378 views::Separator* separator = new views::Separator(); |
| 379 separator->SetColor(kPaletteSeparatorColor); |
| 380 separator->SetBorder(views::CreateEmptyBorder(gfx::Insets( |
| 381 kPaddingBetweenTitleAndSeparator, 0, kMenuSeparatorVerticalPadding, 0))); |
| 382 bubble_view->AddChildView(separator); |
| 383 |
| 384 // Add palette tools. |
| 385 // TODO(tdanderson|jdufault): Use SystemMenuButton to get the material design |
| 386 // ripples. |
| 387 std::vector<PaletteToolView> views = palette_tool_manager_->CreateViews(); |
| 388 for (const PaletteToolView& view : views) |
| 389 bubble_view->AddChildView(view.view); |
| 390 |
| 391 // Show the bubble. |
| 392 bubble_.reset(new ash::TrayBubbleWrapper(this, bubble_view)); |
| 393 SetIsActive(true); |
| 394 } |
| 395 |
| 396 views::TrayBubbleView* PaletteTray::GetBubbleView() { |
| 397 return bubble_ ? bubble_->bubble_view() : nullptr; |
| 398 } |
| 399 |
| 400 void PaletteTray::OnGestureEvent(ui::GestureEvent* event) { |
| 401 if (!drag_controller()->ProcessGestureEvent(event, this)) |
| 402 TrayBackgroundView::OnGestureEvent(event); |
| 403 } |
| 404 |
388 void PaletteTray::UpdateTrayIcon() { | 405 void PaletteTray::UpdateTrayIcon() { |
389 icon_->SetImage(CreateVectorIcon( | 406 icon_->SetImage(CreateVectorIcon( |
390 palette_tool_manager_->GetActiveTrayIcon( | 407 palette_tool_manager_->GetActiveTrayIcon( |
391 palette_tool_manager_->GetActiveTool(ash::PaletteGroup::MODE)), | 408 palette_tool_manager_->GetActiveTool(ash::PaletteGroup::MODE)), |
392 kTrayIconSize, kShelfIconColor)); | 409 kTrayIconSize, kShelfIconColor)); |
393 } | 410 } |
394 | 411 |
395 void PaletteTray::OnPaletteEnabledPrefChanged(bool enabled) { | 412 void PaletteTray::OnPaletteEnabledPrefChanged(bool enabled) { |
396 is_palette_enabled_ = enabled; | 413 is_palette_enabled_ = enabled; |
397 | 414 |
398 if (!enabled) { | 415 if (!enabled) { |
399 SetVisible(false); | 416 SetVisible(false); |
400 palette_tool_manager_->DisableActiveTool(PaletteGroup::MODE); | 417 palette_tool_manager_->DisableActiveTool(PaletteGroup::MODE); |
401 } else { | 418 } else { |
402 UpdateIconVisibility(); | 419 UpdateIconVisibility(); |
403 } | 420 } |
404 } | 421 } |
405 | 422 |
406 void PaletteTray::UpdateIconVisibility() { | 423 void PaletteTray::UpdateIconVisibility() { |
407 SetVisible(is_palette_enabled_ && palette_utils::HasStylusInput() && | 424 SetVisible(is_palette_enabled_ && palette_utils::HasStylusInput() && |
408 ShouldShowOnDisplay(this) && IsInUserSession()); | 425 ShouldShowOnDisplay(this) && IsInUserSession()); |
409 } | 426 } |
410 | 427 |
411 } // namespace ash | 428 } // namespace ash |
OLD | NEW |