Commit 54bfd5a8 authored by Manu Cornet's avatar Manu Cornet Committed by Commit Bot

Create a base class for tooltip bubbles to help with refactoring

Bug: 834392
Change-Id: I4b7f51e74b08e49199b8fd88137b15184db77043
Reviewed-on: https://chromium-review.googlesource.com/1086600Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Manu Cornet <manucornet@chromium.org>
Cr-Commit-Position: refs/heads/master@{#564958}
parent d0bf4841
...@@ -514,6 +514,8 @@ component("ash") { ...@@ -514,6 +514,8 @@ component("ash") {
"shelf/shelf_observer.h", "shelf/shelf_observer.h",
"shelf/shelf_tooltip_bubble.cc", "shelf/shelf_tooltip_bubble.cc",
"shelf/shelf_tooltip_bubble.h", "shelf/shelf_tooltip_bubble.h",
"shelf/shelf_tooltip_bubble_base.cc",
"shelf/shelf_tooltip_bubble_base.h",
"shelf/shelf_tooltip_manager.cc", "shelf/shelf_tooltip_manager.cc",
"shelf/shelf_tooltip_manager.h", "shelf/shelf_tooltip_manager.h",
"shelf/shelf_tooltip_preview_bubble.cc", "shelf/shelf_tooltip_preview_bubble.cc",
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
// found in the LICENSE file. // found in the LICENSE file.
#include "ash/shelf/shelf_tooltip_bubble.h" #include "ash/shelf/shelf_tooltip_bubble.h"
#include "ash/public/cpp/shell_window_ids.h"
#include "ash/system/tray/tray_constants.h" #include "ash/system/tray/tray_constants.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
#include "ui/base/material_design/material_design_controller.h" #include "ui/base/material_design/material_design_controller.h"
...@@ -37,7 +36,7 @@ const int kBorderInteriorThickness = kTooltipHeight / 2; ...@@ -37,7 +36,7 @@ const int kBorderInteriorThickness = kTooltipHeight / 2;
ShelfTooltipBubble::ShelfTooltipBubble(views::View* anchor, ShelfTooltipBubble::ShelfTooltipBubble(views::View* anchor,
views::BubbleBorder::Arrow arrow, views::BubbleBorder::Arrow arrow,
const base::string16& text) const base::string16& text)
: views::BubbleDialogDelegateView(anchor, arrow) { : ShelfTooltipBubbleBase(anchor, arrow) {
set_close_on_deactivate(false); set_close_on_deactivate(false);
set_can_activate(false); set_can_activate(false);
set_accept_events(false); set_accept_events(false);
...@@ -51,7 +50,6 @@ ShelfTooltipBubble::ShelfTooltipBubble(views::View* anchor, ...@@ -51,7 +50,6 @@ ShelfTooltipBubble::ShelfTooltipBubble(views::View* anchor,
theme->GetSystemColor(ui::NativeTheme::kColorId_TooltipText)); theme->GetSystemColor(ui::NativeTheme::kColorId_TooltipText));
SkColor background_color = SkColor background_color =
theme->GetSystemColor(ui::NativeTheme::kColorId_TooltipBackground); theme->GetSystemColor(ui::NativeTheme::kColorId_TooltipBackground);
set_color(background_color);
label->SetBackgroundColor(background_color); label->SetBackgroundColor(background_color);
// The background is not opaque, so we can't do subpixel rendering. // The background is not opaque, so we can't do subpixel rendering.
label->SetSubpixelRenderingEnabled(false); label->SetSubpixelRenderingEnabled(false);
...@@ -65,11 +63,6 @@ ShelfTooltipBubble::ShelfTooltipBubble(views::View* anchor, ...@@ -65,11 +63,6 @@ ShelfTooltipBubble::ShelfTooltipBubble(views::View* anchor,
insets += gfx::Insets(-kBubblePaddingHorizontalBottom); insets += gfx::Insets(-kBubblePaddingHorizontalBottom);
set_anchor_view_insets(insets); set_anchor_view_insets(insets);
// Place the bubble in the same display as the anchor.
set_parent_window(
anchor_widget()->GetNativeWindow()->GetRootWindow()->GetChildById(
kShellWindowId_SettingBubbleContainer));
views::BubbleDialogDelegateView::CreateBubble(this); views::BubbleDialogDelegateView::CreateBubble(this);
if (!ui::MaterialDesignController::IsSecondaryUiMaterial()) { if (!ui::MaterialDesignController::IsSecondaryUiMaterial()) {
// These must both be called after CreateBubble. // These must both be called after CreateBubble.
...@@ -85,8 +78,4 @@ gfx::Size ShelfTooltipBubble::CalculatePreferredSize() const { ...@@ -85,8 +78,4 @@ gfx::Size ShelfTooltipBubble::CalculatePreferredSize() const {
std::max(size.height(), kTooltipMinHeight)); std::max(size.height(), kTooltipMinHeight));
} }
int ShelfTooltipBubble::GetDialogButtons() const {
return ui::DIALOG_BUTTON_NONE;
}
} // namespace ash } // namespace ash
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#define ASH_SHELF_SHELF_TOOLTIP_BUBBLE_H_ #define ASH_SHELF_SHELF_TOOLTIP_BUBBLE_H_
#include "ash/ash_export.h" #include "ash/ash_export.h"
#include "ui/views/bubble/bubble_dialog_delegate.h" #include "ash/shelf/shelf_tooltip_bubble_base.h"
namespace views { namespace views {
class BubbleDialogDelegateView; class BubbleDialogDelegateView;
...@@ -16,7 +16,7 @@ class View; ...@@ -16,7 +16,7 @@ class View;
namespace ash { namespace ash {
// The implementation of tooltip bubbles for the shelf. // The implementation of tooltip bubbles for the shelf.
class ASH_EXPORT ShelfTooltipBubble : public views::BubbleDialogDelegateView { class ASH_EXPORT ShelfTooltipBubble : public ShelfTooltipBubbleBase {
public: public:
ShelfTooltipBubble(views::View* anchor, ShelfTooltipBubble(views::View* anchor,
views::BubbleBorder::Arrow arrow, views::BubbleBorder::Arrow arrow,
...@@ -25,7 +25,6 @@ class ASH_EXPORT ShelfTooltipBubble : public views::BubbleDialogDelegateView { ...@@ -25,7 +25,6 @@ class ASH_EXPORT ShelfTooltipBubble : public views::BubbleDialogDelegateView {
private: private:
// BubbleDialogDelegateView overrides: // BubbleDialogDelegateView overrides:
gfx::Size CalculatePreferredSize() const override; gfx::Size CalculatePreferredSize() const override;
int GetDialogButtons() const override;
DISALLOW_COPY_AND_ASSIGN(ShelfTooltipBubble); DISALLOW_COPY_AND_ASSIGN(ShelfTooltipBubble);
}; };
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/shelf/shelf_tooltip_bubble_base.h"
#include "ash/public/cpp/shell_window_ids.h"
#include "ui/aura/window.h"
namespace ash {
ShelfTooltipBubbleBase::ShelfTooltipBubbleBase(views::View* anchor,
views::BubbleBorder::Arrow arrow)
: views::BubbleDialogDelegateView(anchor, arrow) {
const ui::NativeTheme* theme = anchor_widget()->GetNativeTheme();
SkColor background_color =
theme->GetSystemColor(ui::NativeTheme::kColorId_TooltipBackground);
set_color(background_color);
// Place the bubble in the same display as the anchor.
set_parent_window(
anchor_widget()->GetNativeWindow()->GetRootWindow()->GetChildById(
kShellWindowId_SettingBubbleContainer));
}
int ShelfTooltipBubbleBase::GetDialogButtons() const {
return ui::DIALOG_BUTTON_NONE;
}
} // namespace ash
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_SHELF_SHELF_TOOLTIP_BUBBLE_BASE_H_
#define ASH_SHELF_SHELF_TOOLTIP_BUBBLE_BASE_H_
#include "ash/ash_export.h"
#include "ui/views/bubble/bubble_dialog_delegate.h"
namespace views {
class View;
} // namespace views
namespace ash {
// A base class for all shelf tooltip bubbles.
class ASH_EXPORT ShelfTooltipBubbleBase
: public views::BubbleDialogDelegateView {
public:
ShelfTooltipBubbleBase(views::View* anchor, views::BubbleBorder::Arrow arrow);
private:
// BubbleDialogDelegateView overrides:
int GetDialogButtons() const override;
DISALLOW_COPY_AND_ASSIGN(ShelfTooltipBubbleBase);
};
} // namespace ash
#endif // ASH_SHELF_SHELF_TOOLTIP_BUBBLE_BASE_H_
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "ash/ash_export.h" #include "ash/ash_export.h"
#include "ash/shelf/shelf_observer.h" #include "ash/shelf/shelf_observer.h"
#include "ash/shelf/shelf_tooltip_bubble_base.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/timer/timer.h" #include "base/timer/timer.h"
...@@ -14,7 +15,6 @@ ...@@ -14,7 +15,6 @@
#include "ui/views/pointer_watcher.h" #include "ui/views/pointer_watcher.h"
namespace views { namespace views {
class BubbleDialogDelegateView;
class View; class View;
} }
...@@ -72,7 +72,7 @@ class ASH_EXPORT ShelfTooltipManager : public ui::EventHandler, ...@@ -72,7 +72,7 @@ class ASH_EXPORT ShelfTooltipManager : public ui::EventHandler,
base::OneShotTimer timer_; base::OneShotTimer timer_;
ShelfView* shelf_view_; ShelfView* shelf_view_;
views::BubbleDialogDelegateView* bubble_; ShelfTooltipBubbleBase* bubble_;
base::WeakPtrFactory<ShelfTooltipManager> weak_factory_; base::WeakPtrFactory<ShelfTooltipManager> weak_factory_;
......
...@@ -23,7 +23,7 @@ ShelfTooltipPreviewBubble::ShelfTooltipPreviewBubble( ...@@ -23,7 +23,7 @@ ShelfTooltipPreviewBubble::ShelfTooltipPreviewBubble(
views::View* anchor, views::View* anchor,
views::BubbleBorder::Arrow arrow, views::BubbleBorder::Arrow arrow,
const std::vector<aura::Window*>& windows) const std::vector<aura::Window*>& windows)
: views::BubbleDialogDelegateView(anchor, arrow) { : ShelfTooltipBubbleBase(anchor, arrow) {
// The window previews and titles. // The window previews and titles.
for (auto* window : windows) { for (auto* window : windows) {
wm::WindowMirrorView* preview = new wm::WindowMirrorView( wm::WindowMirrorView* preview = new wm::WindowMirrorView(
...@@ -39,10 +39,6 @@ ShelfTooltipPreviewBubble::ShelfTooltipPreviewBubble( ...@@ -39,10 +39,6 @@ ShelfTooltipPreviewBubble::ShelfTooltipPreviewBubble(
SetStyling(); SetStyling();
PerformLayout(); PerformLayout();
// Place the bubble in the same display as the anchor.
set_parent_window(
anchor_widget()->GetNativeWindow()->GetRootWindow()->GetChildById(
kShellWindowId_SettingBubbleContainer));
set_margins(gfx::Insets(kTooltipPadding, kTooltipPadding)); set_margins(gfx::Insets(kTooltipPadding, kTooltipPadding));
views::BubbleDialogDelegateView::CreateBubble(this); views::BubbleDialogDelegateView::CreateBubble(this);
// This must be done after creating the bubble (a segmentation fault happens // This must be done after creating the bubble (a segmentation fault happens
...@@ -56,8 +52,6 @@ void ShelfTooltipPreviewBubble::SetStyling() { ...@@ -56,8 +52,6 @@ void ShelfTooltipPreviewBubble::SetStyling() {
const ui::NativeTheme* theme = anchor_widget()->GetNativeTheme(); const ui::NativeTheme* theme = anchor_widget()->GetNativeTheme();
SkColor background_color = SkColor background_color =
theme->GetSystemColor(ui::NativeTheme::kColorId_TooltipBackground); theme->GetSystemColor(ui::NativeTheme::kColorId_TooltipBackground);
set_color(background_color);
for (auto* title : titles_) { for (auto* title : titles_) {
title->SetEnabledColor( title->SetEnabledColor(
theme->GetSystemColor(ui::NativeTheme::kColorId_TooltipText)); theme->GetSystemColor(ui::NativeTheme::kColorId_TooltipText));
...@@ -112,8 +106,4 @@ gfx::Size ShelfTooltipPreviewBubble::CalculatePreferredSize() const { ...@@ -112,8 +106,4 @@ gfx::Size ShelfTooltipPreviewBubble::CalculatePreferredSize() const {
return gfx::Size(width_, height_); return gfx::Size(width_, height_);
} }
int ShelfTooltipPreviewBubble::GetDialogButtons() const {
return ui::DIALOG_BUTTON_NONE;
}
} // namespace ash } // namespace ash
...@@ -7,17 +7,15 @@ ...@@ -7,17 +7,15 @@
#include <vector> #include <vector>
#include "ash/public/cpp/shell_window_ids.h" #include "ash/shelf/shelf_tooltip_bubble_base.h"
#include "ash/wm/window_mirror_view.h" #include "ash/wm/window_mirror_view.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
#include "ui/views/bubble/bubble_dialog_delegate.h"
#include "ui/views/controls/label.h" #include "ui/views/controls/label.h"
namespace ash { namespace ash {
// The implementation of tooltip bubbles for the shelf item. // The implementation of tooltip bubbles for the shelf item.
class ASH_EXPORT ShelfTooltipPreviewBubble class ASH_EXPORT ShelfTooltipPreviewBubble : public ShelfTooltipBubbleBase {
: public views::BubbleDialogDelegateView {
public: public:
ShelfTooltipPreviewBubble(views::View* anchor, ShelfTooltipPreviewBubble(views::View* anchor,
views::BubbleBorder::Arrow arrow, views::BubbleBorder::Arrow arrow,
...@@ -30,7 +28,6 @@ class ASH_EXPORT ShelfTooltipPreviewBubble ...@@ -30,7 +28,6 @@ class ASH_EXPORT ShelfTooltipPreviewBubble
// BubbleDialogDelegateView overrides: // BubbleDialogDelegateView overrides:
gfx::Size CalculatePreferredSize() const override; gfx::Size CalculatePreferredSize() const override;
int GetDialogButtons() const override;
// The window previews that this tooltip is meant to display. // The window previews that this tooltip is meant to display.
std::vector<wm::WindowMirrorView*> previews_; std::vector<wm::WindowMirrorView*> previews_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment