Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/shelf/shelf_tooltip_manager.h" | 5 #include "ash/shelf/shelf_tooltip_manager.h" |
| 6 | 6 |
| 7 #include "ash/common/material_design/material_design_controller.h" | |
| 8 #include "ash/common/shelf/shelf_constants.h" | |
| 7 #include "ash/common/shell_window_ids.h" | 9 #include "ash/common/shell_window_ids.h" |
| 8 #include "ash/shelf/shelf.h" | 10 #include "ash/shelf/shelf.h" |
| 9 #include "ash/shelf/shelf_layout_manager.h" | 11 #include "ash/shelf/shelf_layout_manager.h" |
| 10 #include "ash/shelf/shelf_view.h" | 12 #include "ash/shelf/shelf_view.h" |
| 11 #include "ash/shell.h" | 13 #include "ash/shell.h" |
| 12 #include "ash/wm/window_animations.h" | 14 #include "ash/wm/window_animations.h" |
| 13 #include "base/bind.h" | 15 #include "base/bind.h" |
| 14 #include "base/strings/string16.h" | 16 #include "base/strings/string16.h" |
| 15 #include "base/threading/thread_task_runner_handle.h" | 17 #include "base/threading/thread_task_runner_handle.h" |
| 16 #include "base/time/time.h" | 18 #include "base/time/time.h" |
| 17 #include "ui/aura/window.h" | 19 #include "ui/aura/window.h" |
| 18 #include "ui/events/event.h" | 20 #include "ui/events/event.h" |
| 19 #include "ui/events/event_constants.h" | 21 #include "ui/events/event_constants.h" |
| 20 #include "ui/gfx/geometry/insets.h" | 22 #include "ui/gfx/geometry/insets.h" |
| 21 #include "ui/views/bubble/bubble_dialog_delegate.h" | 23 #include "ui/views/bubble/bubble_dialog_delegate.h" |
| 22 #include "ui/views/controls/label.h" | 24 #include "ui/views/controls/label.h" |
| 23 #include "ui/views/layout/fill_layout.h" | 25 #include "ui/views/layout/fill_layout.h" |
| 24 #include "ui/views/widget/widget.h" | 26 #include "ui/views/widget/widget.h" |
| 25 #include "ui/wm/core/window_animations.h" | 27 #include "ui/wm/core/window_animations.h" |
| 26 | 28 |
| 27 namespace ash { | 29 namespace ash { |
| 28 namespace { | 30 namespace { |
| 29 | 31 |
| 30 const int kTooltipTopBottomMargin = 3; | |
| 31 const int kTooltipLeftRightMargin = 10; | |
| 32 const int kTooltipAppearanceDelay = 1000; // msec | 32 const int kTooltipAppearanceDelay = 1000; // msec |
| 33 const int kTooltipMinHeight = 29 - 2 * kTooltipTopBottomMargin; | |
| 34 const SkColor kTooltipTextColor = SkColorSetRGB(0x22, 0x22, 0x22); | 33 const SkColor kTooltipTextColor = SkColorSetRGB(0x22, 0x22, 0x22); |
| 35 | 34 |
| 36 // The maximum width of the tooltip bubble. Borrowed the value from | |
| 37 // ash/tooltip/tooltip_controller.cc | |
| 38 const int kTooltipMaxWidth = 250; | |
| 39 | |
| 40 // The offset for the tooltip bubble - making sure that the bubble is flush | |
| 41 // with the shelf. The offset includes the arrow size in pixels as well as | |
| 42 // the activation bar and other spacing elements. | |
| 43 const int kArrowOffsetLeftRight = 11; | |
| 44 const int kArrowOffsetTopBottom = 7; | |
| 45 | |
| 46 } // namespace | 35 } // namespace |
| 47 | 36 |
| 48 // The implementation of tooltip of the launcher. | 37 // The implementation of tooltip of the launcher. |
| 49 class ShelfTooltipManager::ShelfTooltipBubble | 38 class ShelfTooltipManager::ShelfTooltipBubble |
| 50 : public views::BubbleDialogDelegateView { | 39 : public views::BubbleDialogDelegateView { |
| 51 public: | 40 public: |
| 52 ShelfTooltipBubble(views::View* anchor, | 41 ShelfTooltipBubble(views::View* anchor, |
| 53 views::BubbleBorder::Arrow arrow, | 42 views::BubbleBorder::Arrow arrow, |
| 54 const base::string16& text) | 43 const base::string16& text) |
| 55 : views::BubbleDialogDelegateView(anchor, arrow) { | 44 : views::BubbleDialogDelegateView(anchor, arrow) { |
| 56 gfx::Insets insets = | 45 gfx::Insets insets = |
| 57 gfx::Insets(kArrowOffsetTopBottom, kArrowOffsetLeftRight); | 46 gfx::Insets(GetShelfConstant(TOOLTIP_ARROW_TOP_BOTTOM_OFFSET), |
| 47 GetShelfConstant(TOOLTIP_ARROW_LEFT_RIGHT_OFFSET)); | |
| 58 // Adjust the anchor location for asymmetrical borders of shelf item. | 48 // Adjust the anchor location for asymmetrical borders of shelf item. |
| 59 if (anchor->border()) | 49 if (anchor->border()) |
| 60 insets += anchor->border()->GetInsets(); | 50 insets += anchor->border()->GetInsets(); |
| 61 | 51 |
| 62 set_anchor_view_insets(insets); | 52 set_anchor_view_insets(insets); |
| 63 set_close_on_deactivate(false); | 53 set_close_on_deactivate(false); |
| 64 set_can_activate(false); | 54 set_can_activate(false); |
| 65 set_accept_events(false); | 55 set_accept_events(false); |
| 66 set_margins(gfx::Insets(kTooltipTopBottomMargin, kTooltipLeftRightMargin)); | 56 set_margins(gfx::Insets(GetShelfConstant(TOOLTIP_TOP_BOTTOM_MARGIN), |
| 67 set_shadow(views::BubbleBorder::SMALL_SHADOW); | 57 GetShelfConstant(TOOLTIP_LEFT_RIGHT_MARGIN))); |
| 58 const bool material = ash::MaterialDesignController::IsTooltipMaterial(); | |
| 59 set_shadow(material ? views::BubbleBorder::NO_ASSETS_TOOLTIP | |
|
msw
2016/07/22 16:51:06
driveby: Can you use the existing NO_ASSETS settin
varkha
2016/07/22 22:03:56
views::BubbleBorder::NO_ASSETS results in huge ver
msw
2016/07/22 22:14:52
There's only one user; SubtleNotificationView. Per
msw
2016/07/22 22:16:25
Oops, there are multiple users; but the same thoug
varkha
2016/07/23 01:09:42
Yes, the margins that are settable with set_margin
| |
| 60 : views::BubbleBorder::SMALL_SHADOW); | |
| 68 SetLayoutManager(new views::FillLayout()); | 61 SetLayoutManager(new views::FillLayout()); |
| 69 // The anchor may not have the widget in tests. | 62 // The anchor may not have the widget in tests. |
| 70 if (anchor->GetWidget() && anchor->GetWidget()->GetNativeWindow()) { | 63 if (anchor->GetWidget() && anchor->GetWidget()->GetNativeWindow()) { |
| 71 set_parent_window(ash::Shell::GetContainer( | 64 set_parent_window(ash::Shell::GetContainer( |
| 72 anchor->GetWidget()->GetNativeWindow()->GetRootWindow(), | 65 anchor->GetWidget()->GetNativeWindow()->GetRootWindow(), |
| 73 ash::kShellWindowId_SettingBubbleContainer)); | 66 ash::kShellWindowId_SettingBubbleContainer)); |
| 74 } | 67 } |
| 75 views::Label* label = new views::Label(text); | 68 views::Label* label = new views::Label(text); |
| 76 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 69 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 77 label->SetEnabledColor(kTooltipTextColor); | 70 ui::NativeTheme* theme = anchor->GetWidget()->GetNativeTheme(); |
| 71 SkColor text_color = | |
| 72 material ? theme->GetSystemColor(ui::NativeTheme::kColorId_TooltipText) | |
| 73 : kTooltipTextColor; | |
| 74 label->SetEnabledColor(text_color); | |
| 75 if (material) { | |
| 76 SkColor background_color = | |
| 77 theme->GetSystemColor(ui::NativeTheme::kColorId_TooltipBackground); | |
| 78 set_color(background_color); | |
| 79 label->SetBackgroundColor(background_color); | |
| 80 } | |
| 78 AddChildView(label); | 81 AddChildView(label); |
| 79 views::BubbleDialogDelegateView::CreateBubble(this); | 82 views::BubbleDialogDelegateView::CreateBubble(this); |
| 83 // The bubble border has its own background so the background created by the | |
| 84 // BubbleDialogDelegateView is redundant and would cause extra opacity. | |
| 85 if (material) | |
| 86 set_background(nullptr); | |
| 87 SetArrowPaintType(material ? views::BubbleBorder::PAINT_TRANSPARENT | |
| 88 : views::BubbleBorder::PAINT_NORMAL); | |
| 80 } | 89 } |
| 81 | 90 |
| 82 private: | 91 private: |
| 83 // BubbleDialogDelegateView overrides: | 92 // BubbleDialogDelegateView overrides: |
| 84 gfx::Size GetPreferredSize() const override { | 93 gfx::Size GetPreferredSize() const override { |
| 85 const gfx::Size size = BubbleDialogDelegateView::GetPreferredSize(); | 94 const gfx::Size size = BubbleDialogDelegateView::GetPreferredSize(); |
| 95 const int kTooltipMinHeight = | |
| 96 GetShelfConstant(TOOLTIP_HEIGHT) - | |
| 97 2 * GetShelfConstant(TOOLTIP_TOP_BOTTOM_MARGIN); | |
| 98 const int kTooltipMaxWidth = GetShelfConstant(TOOLTIP_MAX_WIDTH); | |
| 86 return gfx::Size(std::min(size.width(), kTooltipMaxWidth), | 99 return gfx::Size(std::min(size.width(), kTooltipMaxWidth), |
| 87 std::max(size.height(), kTooltipMinHeight)); | 100 std::max(size.height(), kTooltipMinHeight)); |
| 88 } | 101 } |
| 89 | 102 |
| 90 int GetDialogButtons() const override { return ui::DIALOG_BUTTON_NONE; } | 103 int GetDialogButtons() const override { return ui::DIALOG_BUTTON_NONE; } |
| 91 | 104 |
| 92 DISALLOW_COPY_AND_ASSIGN(ShelfTooltipBubble); | 105 DISALLOW_COPY_AND_ASSIGN(ShelfTooltipBubble); |
| 93 }; | 106 }; |
| 94 | 107 |
| 95 ShelfTooltipManager::ShelfTooltipManager(ShelfView* shelf_view) | 108 ShelfTooltipManager::ShelfTooltipManager(ShelfView* shelf_view) |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 250 base::Bind(&ShelfTooltipManager::Close, weak_factory_.GetWeakPtr())); | 263 base::Bind(&ShelfTooltipManager::Close, weak_factory_.GetWeakPtr())); |
| 251 } | 264 } |
| 252 } | 265 } |
| 253 | 266 |
| 254 bool ShelfTooltipManager::ShouldShowTooltipForView(views::View* view) { | 267 bool ShelfTooltipManager::ShouldShowTooltipForView(views::View* view) { |
| 255 return shelf_view_ && shelf_view_->ShouldShowTooltipForView(view) && | 268 return shelf_view_ && shelf_view_->ShouldShowTooltipForView(view) && |
| 256 shelf_layout_manager_ && shelf_layout_manager_->IsVisible(); | 269 shelf_layout_manager_ && shelf_layout_manager_->IsVisible(); |
| 257 } | 270 } |
| 258 | 271 |
| 259 } // namespace ash | 272 } // namespace ash |
| OLD | NEW |