| 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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 SetInkDropMode(InkDropMode::ON); | 146 SetInkDropMode(InkDropMode::ON); |
| 147 SetLayoutManager(new views::FillLayout()); | 147 SetLayoutManager(new views::FillLayout()); |
| 148 icon_ = new views::ImageView(); | 148 icon_ = new views::ImageView(); |
| 149 UpdateTrayIcon(); | 149 UpdateTrayIcon(); |
| 150 | 150 |
| 151 tray_container()->SetMargin(kTrayIconMainAxisInset, kTrayIconCrossAxisInset); | 151 tray_container()->SetMargin(kTrayIconMainAxisInset, kTrayIconCrossAxisInset); |
| 152 tray_container()->AddChildView(icon_); | 152 tray_container()->AddChildView(icon_); |
| 153 | 153 |
| 154 Shell::Get()->AddShellObserver(this); | 154 Shell::Get()->AddShellObserver(this); |
| 155 ui::InputDeviceManager::GetInstance()->AddObserver(this); | 155 ui::InputDeviceManager::GetInstance()->AddObserver(this); |
| 156 |
| 157 if (!drag_controller()) |
| 158 set_drag_controller(base::MakeUnique<TrayDragController>(shelf)); |
| 156 } | 159 } |
| 157 | 160 |
| 158 PaletteTray::~PaletteTray() { | 161 PaletteTray::~PaletteTray() { |
| 159 if (bubble_) | 162 if (bubble_) |
| 160 bubble_->bubble_view()->ResetDelegate(); | 163 bubble_->bubble_view()->ResetDelegate(); |
| 161 | 164 |
| 162 ui::InputDeviceManager::GetInstance()->RemoveObserver(this); | 165 ui::InputDeviceManager::GetInstance()->RemoveObserver(this); |
| 163 Shell::Get()->RemoveShellObserver(this); | 166 Shell::Get()->RemoveShellObserver(this); |
| 164 } | 167 } |
| 165 | 168 |
| 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) { | 169 bool PaletteTray::ContainsPointInScreen(const gfx::Point& point) { |
| 229 if (icon_ && icon_->GetBoundsInScreen().Contains(point)) | 170 if (icon_ && icon_->GetBoundsInScreen().Contains(point)) |
| 230 return true; | 171 return true; |
| 231 | 172 |
| 232 return bubble_ && bubble_->bubble_view()->GetBoundsInScreen().Contains(point); | 173 return bubble_ && bubble_->bubble_view()->GetBoundsInScreen().Contains(point); |
| 233 } | 174 } |
| 234 | 175 |
| 235 void PaletteTray::OnSessionStateChanged(session_manager::SessionState state) { | 176 void PaletteTray::OnSessionStateChanged(session_manager::SessionState state) { |
| 236 UpdateIconVisibility(); | 177 UpdateIconVisibility(); |
| 237 } | 178 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 | 214 |
| 274 // Don't do anything if the palette should not be shown or if the user has | 215 // Don't do anything if the palette should not be shown or if the user has |
| 275 // disabled it all-together. | 216 // disabled it all-together. |
| 276 if (!IsInUserSession() || !palette_delegate->ShouldShowPalette()) | 217 if (!IsInUserSession() || !palette_delegate->ShouldShowPalette()) |
| 277 return; | 218 return; |
| 278 | 219 |
| 279 // Auto show/hide the palette if allowed by the user. | 220 // Auto show/hide the palette if allowed by the user. |
| 280 if (palette_delegate->ShouldAutoOpenPalette()) { | 221 if (palette_delegate->ShouldAutoOpenPalette()) { |
| 281 if (stylus_state == ui::StylusState::REMOVED && !bubble_) { | 222 if (stylus_state == ui::StylusState::REMOVED && !bubble_) { |
| 282 is_bubble_auto_opened_ = true; | 223 is_bubble_auto_opened_ = true; |
| 283 ShowPalette(); | 224 ShowBubble(); |
| 284 } else if (stylus_state == ui::StylusState::INSERTED && bubble_) { | 225 } else if (stylus_state == ui::StylusState::INSERTED && bubble_) { |
| 285 HidePalette(); | 226 HidePalette(); |
| 286 } | 227 } |
| 287 } | 228 } |
| 288 | 229 |
| 289 // Disable any active modes if the stylus has been inserted. | 230 // Disable any active modes if the stylus has been inserted. |
| 290 if (stylus_state == ui::StylusState::INSERTED) | 231 if (stylus_state == ui::StylusState::INSERTED) |
| 291 palette_tool_manager_->DisableActiveTool(PaletteGroup::MODE); | 232 palette_tool_manager_->DisableActiveTool(PaletteGroup::MODE); |
| 292 } | 233 } |
| 293 | 234 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 // |delegate| can be null in tests. | 319 // |delegate| can be null in tests. |
| 379 if (!delegate) | 320 if (!delegate) |
| 380 return; | 321 return; |
| 381 | 322 |
| 382 // OnPaletteEnabledPrefChanged will get called with the initial pref value, | 323 // OnPaletteEnabledPrefChanged will get called with the initial pref value, |
| 383 // which will take care of showing the palette. | 324 // which will take care of showing the palette. |
| 384 palette_enabled_subscription_ = delegate->AddPaletteEnableListener(base::Bind( | 325 palette_enabled_subscription_ = delegate->AddPaletteEnableListener(base::Bind( |
| 385 &PaletteTray::OnPaletteEnabledPrefChanged, weak_factory_.GetWeakPtr())); | 326 &PaletteTray::OnPaletteEnabledPrefChanged, weak_factory_.GetWeakPtr())); |
| 386 } | 327 } |
| 387 | 328 |
| 329 bool PaletteTray::PerformAction(const ui::Event& event) { |
| 330 if (bubble_) { |
| 331 if (num_actions_in_bubble_ == 0) |
| 332 RecordPaletteOptionsUsage(PaletteTrayOptions::PALETTE_CLOSED_NO_ACTION); |
| 333 HidePalette(); |
| 334 return true; |
| 335 } |
| 336 |
| 337 ShowBubble(); |
| 338 return true; |
| 339 } |
| 340 |
| 341 void PaletteTray::CloseBubble() { |
| 342 HidePalette(); |
| 343 } |
| 344 |
| 345 void PaletteTray::ShowBubble() { |
| 346 if (bubble_) |
| 347 return; |
| 348 |
| 349 DCHECK(tray_container()); |
| 350 |
| 351 views::TrayBubbleView::InitParams init_params; |
| 352 init_params.delegate = this; |
| 353 init_params.parent_window = GetBubbleWindowContainer(); |
| 354 init_params.anchor_view = GetBubbleAnchor(); |
| 355 init_params.anchor_alignment = GetAnchorAlignment(); |
| 356 init_params.min_width = kPaletteWidth; |
| 357 init_params.max_width = kPaletteWidth; |
| 358 init_params.close_on_deactivate = true; |
| 359 |
| 360 // TODO(tdanderson): Refactor into common row layout code. |
| 361 // TODO(tdanderson|jdufault): Add material design ripple effects to the menu |
| 362 // rows. |
| 363 |
| 364 // Create and customize bubble view. |
| 365 views::TrayBubbleView* bubble_view = new views::TrayBubbleView(init_params); |
| 366 bubble_view->set_anchor_view_insets(GetBubbleAnchorInsets()); |
| 367 bubble_view->set_margins( |
| 368 gfx::Insets(kPalettePaddingOnTop, 0, kPalettePaddingOnBottom, 0)); |
| 369 |
| 370 // Add title. |
| 371 auto* title_view = new TitleView(this); |
| 372 title_view->SetBorder(views::CreateEmptyBorder( |
| 373 gfx::Insets(0, kPaddingBetweenTitleAndLeftEdge, 0, 0))); |
| 374 bubble_view->AddChildView(title_view); |
| 375 |
| 376 // Add horizontal separator. |
| 377 views::Separator* separator = new views::Separator(); |
| 378 separator->SetColor(kPaletteSeparatorColor); |
| 379 separator->SetBorder(views::CreateEmptyBorder(gfx::Insets( |
| 380 kPaddingBetweenTitleAndSeparator, 0, kMenuSeparatorVerticalPadding, 0))); |
| 381 bubble_view->AddChildView(separator); |
| 382 |
| 383 // Add palette tools. |
| 384 // TODO(tdanderson|jdufault): Use SystemMenuButton to get the material design |
| 385 // ripples. |
| 386 std::vector<PaletteToolView> views = palette_tool_manager_->CreateViews(); |
| 387 for (const PaletteToolView& view : views) |
| 388 bubble_view->AddChildView(view.view); |
| 389 |
| 390 // Show the bubble. |
| 391 bubble_ = base::MakeUnique<ash::TrayBubbleWrapper>(this, bubble_view); |
| 392 SetIsActive(true); |
| 393 } |
| 394 |
| 395 views::TrayBubbleView* PaletteTray::GetBubbleView() { |
| 396 return bubble_ ? bubble_->bubble_view() : nullptr; |
| 397 } |
| 398 |
| 388 void PaletteTray::UpdateTrayIcon() { | 399 void PaletteTray::UpdateTrayIcon() { |
| 389 icon_->SetImage(CreateVectorIcon( | 400 icon_->SetImage(CreateVectorIcon( |
| 390 palette_tool_manager_->GetActiveTrayIcon( | 401 palette_tool_manager_->GetActiveTrayIcon( |
| 391 palette_tool_manager_->GetActiveTool(ash::PaletteGroup::MODE)), | 402 palette_tool_manager_->GetActiveTool(ash::PaletteGroup::MODE)), |
| 392 kTrayIconSize, kShelfIconColor)); | 403 kTrayIconSize, kShelfIconColor)); |
| 393 } | 404 } |
| 394 | 405 |
| 395 void PaletteTray::OnPaletteEnabledPrefChanged(bool enabled) { | 406 void PaletteTray::OnPaletteEnabledPrefChanged(bool enabled) { |
| 396 is_palette_enabled_ = enabled; | 407 is_palette_enabled_ = enabled; |
| 397 | 408 |
| 398 if (!enabled) { | 409 if (!enabled) { |
| 399 SetVisible(false); | 410 SetVisible(false); |
| 400 palette_tool_manager_->DisableActiveTool(PaletteGroup::MODE); | 411 palette_tool_manager_->DisableActiveTool(PaletteGroup::MODE); |
| 401 } else { | 412 } else { |
| 402 UpdateIconVisibility(); | 413 UpdateIconVisibility(); |
| 403 } | 414 } |
| 404 } | 415 } |
| 405 | 416 |
| 406 void PaletteTray::UpdateIconVisibility() { | 417 void PaletteTray::UpdateIconVisibility() { |
| 407 SetVisible(is_palette_enabled_ && palette_utils::HasStylusInput() && | 418 SetVisible(is_palette_enabled_ && palette_utils::HasStylusInput() && |
| 408 ShouldShowOnDisplay(this) && IsInUserSession()); | 419 ShouldShowOnDisplay(this) && IsInUserSession()); |
| 409 } | 420 } |
| 410 | 421 |
| 411 } // namespace ash | 422 } // namespace ash |
| OLD | NEW |