summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ash/shell.cc6
-rw-r--r--chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc9
-rw-r--r--ui/views/corewm/tooltip.h4
-rw-r--r--ui/views/corewm/tooltip_aura.cc26
-rw-r--r--ui/views/corewm/tooltip_aura.h9
-rw-r--r--ui/views/corewm/tooltip_controller.cc11
-rw-r--r--ui/views/corewm/tooltip_controller.h2
-rw-r--r--ui/views/corewm/tooltip_controller_unittest.cc6
-rw-r--r--ui/views/corewm/tooltip_win.cc17
-rw-r--r--ui/views/corewm/tooltip_win.h16
-rw-r--r--ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc2
-rw-r--r--ui/views/widget/tooltip_manager.cc24
-rw-r--r--ui/views/widget/tooltip_manager.h13
-rw-r--r--ui/views/widget/tooltip_manager_aura.cc6
-rw-r--r--ui/views/widget/tooltip_manager_aura.h2
-rw-r--r--ui/wm/public/tooltip_client.h8
16 files changed, 82 insertions, 79 deletions
diff --git a/ash/shell.cc b/ash/shell.cc
index b51a75a..eebf156 100644
--- a/ash/shell.cc
+++ b/ash/shell.cc
@@ -990,10 +990,8 @@ void Shell::Init(const ShellInitParams& init_params) {
window_selector_controller_.reset(new WindowSelectorController());
window_cycle_controller_.reset(new WindowCycleController());
- tooltip_controller_.reset(
- new views::corewm::TooltipController(
- scoped_ptr<views::corewm::Tooltip>(
- new views::corewm::TooltipAura(gfx::SCREEN_TYPE_ALTERNATE))));
+ tooltip_controller_.reset(new views::corewm::TooltipController(
+ scoped_ptr<views::corewm::Tooltip>(new views::corewm::TooltipAura)));
AddPreTargetHandler(tooltip_controller_.get());
event_client_.reset(new EventClientImpl);
diff --git a/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc b/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc
index 506ee3e..afe033a 100644
--- a/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc
+++ b/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc
@@ -690,11 +690,10 @@ base::string16 BookmarkBarView::CreateToolTipForURLAndTitle(
const GURL& url,
const base::string16& title,
Profile* profile) {
- int max_width = views::TooltipManager::GetMaxWidth(
- screen_loc.x(),
- screen_loc.y(),
- widget->GetNativeView());
- const gfx::FontList tt_fonts = widget->GetTooltipManager()->GetFontList();
+ const views::TooltipManager* tooltip_manager = widget->GetTooltipManager();
+ int max_width = tooltip_manager->GetMaxWidth(screen_loc,
+ widget->GetNativeView());
+ const gfx::FontList tt_fonts = tooltip_manager->GetFontList();
base::string16 result;
// First the title.
diff --git a/ui/views/corewm/tooltip.h b/ui/views/corewm/tooltip.h
index 7fb15bc..b8e6803 100644
--- a/ui/views/corewm/tooltip.h
+++ b/ui/views/corewm/tooltip.h
@@ -25,6 +25,10 @@ class VIEWS_EXPORT Tooltip {
public:
virtual ~Tooltip() {}
+ // Returns the max width of the tooltip when shown at the specified location.
+ virtual int GetMaxWidth(const gfx::Point& location,
+ aura::Window* context) const = 0;
+
// Updates the text on the tooltip and resizes to fit.
virtual void SetText(aura::Window* window,
const base::string16& tooltip_text,
diff --git a/ui/views/corewm/tooltip_aura.cc b/ui/views/corewm/tooltip_aura.cc
index ef69bbc..3e98cf16 100644
--- a/ui/views/corewm/tooltip_aura.cc
+++ b/ui/views/corewm/tooltip_aura.cc
@@ -47,9 +47,8 @@ views::Widget* CreateTooltipWidget(aura::Window* tooltip_window) {
namespace views {
namespace corewm {
-TooltipAura::TooltipAura(gfx::ScreenType screen_type)
- : screen_type_(screen_type),
- widget_(NULL),
+TooltipAura::TooltipAura()
+ : widget_(NULL),
tooltip_window_(NULL) {
label_.set_owned_by_client();
label_.SetMultiLine(true);
@@ -142,19 +141,11 @@ void TooltipAura::TrimTooltipToFit(const gfx::FontList& font_list,
*text = result;
}
-int TooltipAura::GetMaxWidth(const gfx::Point& location) const {
- // TODO(varunjain): implementation duplicated in tooltip_manager_aura. Figure
- // out a way to merge.
- gfx::Screen* screen = gfx::Screen::GetScreenByType(screen_type_);
- gfx::Rect display_bounds(screen->GetDisplayNearestPoint(location).bounds());
- return (display_bounds.width() + 1) / 2;
-}
-
void TooltipAura::SetTooltipBounds(const gfx::Point& mouse_pos,
const gfx::Size& tooltip_size) {
gfx::Rect tooltip_rect(mouse_pos, tooltip_size);
tooltip_rect.Offset(kCursorOffsetX, kCursorOffsetY);
- gfx::Screen* screen = gfx::Screen::GetScreenByType(screen_type_);
+ gfx::Screen* screen = gfx::Screen::GetScreenFor(tooltip_window_);
gfx::Rect display_bounds(screen->GetDisplayNearestPoint(mouse_pos).bounds());
// If tooltip is out of bounds on the x axis, we simply shift it
@@ -181,6 +172,13 @@ void TooltipAura::DestroyWidget() {
}
}
+int TooltipAura::GetMaxWidth(const gfx::Point& location,
+ aura::Window* context) const {
+ gfx::Screen* screen = gfx::Screen::GetScreenFor(context);
+ gfx::Rect display_bounds(screen->GetDisplayNearestPoint(location).bounds());
+ return std::min(kTooltipMaxWidthPixels, (display_bounds.width() + 1) / 2);
+}
+
void TooltipAura::SetText(aura::Window* window,
const base::string16& tooltip_text,
const gfx::Point& location) {
@@ -188,8 +186,8 @@ void TooltipAura::SetText(aura::Window* window,
int max_width = 0;
int line_count = 0;
base::string16 trimmed_text(tooltip_text);
- TrimTooltipToFit(label_.font_list(), GetMaxWidth(location), &trimmed_text,
- &max_width, &line_count);
+ TrimTooltipToFit(label_.font_list(), GetMaxWidth(location, window),
+ &trimmed_text, &max_width, &line_count);
label_.SetText(trimmed_text);
if (!widget_) {
diff --git a/ui/views/corewm/tooltip_aura.h b/ui/views/corewm/tooltip_aura.h
index 07952b6..ce92fa2 100644
--- a/ui/views/corewm/tooltip_aura.h
+++ b/ui/views/corewm/tooltip_aura.h
@@ -23,7 +23,7 @@ namespace corewm {
// Implementation of Tooltip that shows the tooltip using a Widget and Label.
class VIEWS_EXPORT TooltipAura : public Tooltip, public WidgetObserver {
public:
- explicit TooltipAura(gfx::ScreenType screen_type);
+ TooltipAura();
~TooltipAura() override;
// Trims the tooltip to fit in the width |max_width|, setting |text| to the
@@ -37,9 +37,6 @@ class VIEWS_EXPORT TooltipAura : public Tooltip, public WidgetObserver {
int* line_count);
private:
- // Returns the max width of the tooltip when shown at the specified location.
- int GetMaxWidth(const gfx::Point& location) const;
-
// Adjusts the bounds given by the arguments to fit inside the desktop
// and applies the adjusted bounds to the label_.
void SetTooltipBounds(const gfx::Point& mouse_pos,
@@ -49,6 +46,8 @@ class VIEWS_EXPORT TooltipAura : public Tooltip, public WidgetObserver {
void DestroyWidget();
// Tooltip:
+ int GetMaxWidth(const gfx::Point& location,
+ aura::Window* context) const override;
void SetText(aura::Window* window,
const base::string16& tooltip_text,
const gfx::Point& location) override;
@@ -59,8 +58,6 @@ class VIEWS_EXPORT TooltipAura : public Tooltip, public WidgetObserver {
// WidgetObserver:
void OnWidgetDestroying(Widget* widget) override;
- const gfx::ScreenType screen_type_;
-
// The label showing the tooltip.
Label label_;
diff --git a/ui/views/corewm/tooltip_controller.cc b/ui/views/corewm/tooltip_controller.cc
index 0408f5d..8af7199 100644
--- a/ui/views/corewm/tooltip_controller.cc
+++ b/ui/views/corewm/tooltip_controller.cc
@@ -17,6 +17,7 @@
#include "ui/gfx/font.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/screen.h"
+#include "ui/gfx/text_elider.h"
#include "ui/views/corewm/tooltip.h"
#include "ui/views/widget/tooltip_manager.h"
#include "ui/wm/public/drag_drop_client.h"
@@ -27,6 +28,7 @@ namespace {
const int kTooltipTimeoutMs = 500;
const int kDefaultTooltipShownTimeoutMs = 10000;
+const size_t kMaxTooltipLength = 1024;
// Returns true if |target| is a valid window to get the tooltip from.
// |event_target| is the original target from the event and |target| the window
@@ -129,6 +131,11 @@ TooltipController::~TooltipController() {
tooltip_window_->RemoveObserver(this);
}
+int TooltipController::GetMaxWidth(const gfx::Point& location,
+ gfx::NativeView context) const {
+ return tooltip_->GetMaxWidth(location, context);
+}
+
void TooltipController::UpdateTooltip(aura::Window* target) {
// If tooltip is visible, we may want to hide it. If it is not, we are ok.
if (tooltip_window_ == target && tooltip_->IsVisible())
@@ -298,8 +305,8 @@ void TooltipController::UpdateIfRequired() {
if (tooltip_text_ != tooltip_text || !tooltip_->IsVisible() || ids_differ) {
tooltip_shown_timer_.Stop();
tooltip_text_ = tooltip_text;
- base::string16 trimmed_text(tooltip_text_);
- views::TooltipManager::TrimTooltipText(&trimmed_text);
+ base::string16 trimmed_text =
+ gfx::TruncateString(tooltip_text_, kMaxTooltipLength, gfx::WORD_BREAK);
// If the string consists entirely of whitespace, then don't both showing it
// (an empty tooltip is useless).
base::string16 whitespace_removed_text;
diff --git a/ui/views/corewm/tooltip_controller.h b/ui/views/corewm/tooltip_controller.h
index 87500b3..2f8c7ef 100644
--- a/ui/views/corewm/tooltip_controller.h
+++ b/ui/views/corewm/tooltip_controller.h
@@ -38,6 +38,8 @@ class VIEWS_EXPORT TooltipController : public aura::client::TooltipClient,
~TooltipController() override;
// Overridden from aura::client::TooltipClient.
+ int GetMaxWidth(const gfx::Point& location,
+ aura::Window* context) const override;
void UpdateTooltip(aura::Window* target) override;
void SetTooltipShownTimeout(aura::Window* target, int timeout_in_ms) override;
void SetTooltipsEnabled(bool enable) override;
diff --git a/ui/views/corewm/tooltip_controller_unittest.cc b/ui/views/corewm/tooltip_controller_unittest.cc
index 0ce3fb4..ad341d9 100644
--- a/ui/views/corewm/tooltip_controller_unittest.cc
+++ b/ui/views/corewm/tooltip_controller_unittest.cc
@@ -90,7 +90,7 @@ class TooltipControllerTest : public aura::test::AuraTestBase {
#if defined(OS_CHROMEOS)
controller_.reset(new TooltipController(
scoped_ptr<views::corewm::Tooltip>(
- new views::corewm::TooltipAura(gfx::SCREEN_TYPE_ALTERNATE))));
+ new views::corewm::TooltipAura)));
root_window()->AddPreTargetHandler(controller_.get());
SetTooltipClient(root_window(), controller_.get());
#endif
@@ -532,6 +532,10 @@ class TestTooltip : public Tooltip {
const base::string16& tooltip_text() const { return tooltip_text_; }
// Tooltip:
+ int GetMaxWidth(const gfx::Point& location,
+ aura::Window* context) const override {
+ return 100;
+ }
void SetText(aura::Window* window,
const base::string16& tooltip_text,
const gfx::Point& location) override {
diff --git a/ui/views/corewm/tooltip_win.cc b/ui/views/corewm/tooltip_win.cc
index 15d90ac..46635d2 100644
--- a/ui/views/corewm/tooltip_win.cc
+++ b/ui/views/corewm/tooltip_win.cc
@@ -95,6 +95,16 @@ void TooltipWin::PositionTooltip() {
0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
}
+int TooltipWin::GetMaxWidth(const gfx::Point& location,
+ aura::Window* context) const {
+ // This code only runs for non-metro, so GetNativeScreen() is fine.
+ const gfx::Point screen_point = gfx::win::DIPToScreenPoint(location);
+ gfx::Display display(
+ gfx::Screen::GetNativeScreen()->GetDisplayNearestPoint(screen_point));
+ const gfx::Rect monitor_bounds = display.bounds();
+ return (monitor_bounds.width() + 1) / 2;
+}
+
void TooltipWin::SetText(aura::Window* window,
const base::string16& tooltip_text,
const gfx::Point& location) {
@@ -116,12 +126,7 @@ void TooltipWin::SetText(aura::Window* window,
SendMessage(tooltip_hwnd_, TTM_SETTOOLINFO, 0,
reinterpret_cast<LPARAM>(&toolinfo_));
- // This code only runs for non-metro, so GetNativeScreen() is fine.
- const gfx::Point screen_point = gfx::win::DIPToScreenPoint(location_);
- gfx::Display display(
- gfx::Screen::GetNativeScreen()->GetDisplayNearestPoint(screen_point));
- const gfx::Rect monitor_bounds = display.bounds();
- int max_width = (monitor_bounds.width() + 1) / 2;
+ int max_width = GetMaxWidth(location_, window);
SendMessage(tooltip_hwnd_, TTM_SETMAXTIPWIDTH, 0, max_width);
}
diff --git a/ui/views/corewm/tooltip_win.h b/ui/views/corewm/tooltip_win.h
index 3f3e51b..9fac064 100644
--- a/ui/views/corewm/tooltip_win.h
+++ b/ui/views/corewm/tooltip_win.h
@@ -22,7 +22,7 @@ namespace corewm {
class VIEWS_EXPORT TooltipWin : public Tooltip {
public:
explicit TooltipWin(HWND parent);
- virtual ~TooltipWin();
+ ~TooltipWin() override;
// HandleNotify() is forwarded from DesktopWindowTreeHostWin to keep the
// native tooltip in sync.
@@ -37,12 +37,14 @@ class VIEWS_EXPORT TooltipWin : public Tooltip {
void PositionTooltip();
// Tooltip:
- virtual void SetText(aura::Window* window,
- const base::string16& tooltip_text,
- const gfx::Point& location) override;
- virtual void Show() override;
- virtual void Hide() override;
- virtual bool IsVisible() override;
+ int GetMaxWidth(const gfx::Point& location,
+ aura::Window* context) const override;
+ void SetText(aura::Window* window,
+ const base::string16& tooltip_text,
+ const gfx::Point& location) override;
+ void Show() override;
+ void Hide() override;
+ bool IsVisible() override;
// The window |tooltip_hwnd_| is parented to.
HWND parent_hwnd_;
diff --git a/ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc b/ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc
index 3874e67..784446e2 100644
--- a/ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc
+++ b/ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc
@@ -289,7 +289,7 @@ void DesktopWindowTreeHostX11::OnNativeWidgetCreated(
}
scoped_ptr<corewm::Tooltip> DesktopWindowTreeHostX11::CreateTooltip() {
- return make_scoped_ptr(new corewm::TooltipAura(gfx::SCREEN_TYPE_NATIVE));
+ return make_scoped_ptr(new corewm::TooltipAura);
}
scoped_ptr<aura::client::DragDropClient>
diff --git a/ui/views/widget/tooltip_manager.cc b/ui/views/widget/tooltip_manager.cc
index b2e6827..c5e641a 100644
--- a/ui/views/widget/tooltip_manager.cc
+++ b/ui/views/widget/tooltip_manager.cc
@@ -4,33 +4,9 @@
#include "ui/views/widget/tooltip_manager.h"
-#include "ui/gfx/geometry/rect.h"
-#include "ui/gfx/screen.h"
-#include "ui/gfx/text_elider.h"
-
namespace views {
-const size_t kMaxTooltipLength = 1024;
-
// static
const char TooltipManager::kGroupingPropertyKey[] = "GroupingPropertyKey";
-// static
-int TooltipManager::GetMaxWidth(int x, int y, gfx::NativeView context) {
- return GetMaxWidth(gfx::Screen::GetScreenFor(context)->GetDisplayNearestPoint(
- gfx::Point(x, y)));
-}
-
-// static
-int TooltipManager::GetMaxWidth(const gfx::Display& display) {
- return (display.bounds().width() + 1) / 2;
-}
-
-// static
-void TooltipManager::TrimTooltipText(base::string16* text) {
- // Clamp the tooltip length to kMaxTooltipLength so that we don't
- // accidentally DOS the user with a mega tooltip.
- *text = gfx::TruncateString(*text, kMaxTooltipLength, gfx::WORD_BREAK);
-}
-
} // namespace views
diff --git a/ui/views/widget/tooltip_manager.h b/ui/views/widget/tooltip_manager.h
index 828d4f4..4145db4 100644
--- a/ui/views/widget/tooltip_manager.h
+++ b/ui/views/widget/tooltip_manager.h
@@ -15,6 +15,7 @@
namespace gfx {
class Display;
class FontList;
+class Point;
} // namespace gfx
namespace views {
@@ -38,17 +39,11 @@ class VIEWS_EXPORT TooltipManager {
TooltipManager() {}
virtual ~TooltipManager() {}
- // Returns the maximum width of the tooltip. |x| and |y| give the location
+ // Returns the maximum width of the tooltip. |point| gives the location
// the tooltip is to be displayed on in screen coordinates. |context| is
// used to determine which gfx::Screen should be used.
- static int GetMaxWidth(int x, int y, gfx::NativeView context);
-
- // Same as GetMaxWidth(), but takes a Display.
- static int GetMaxWidth(const gfx::Display& display);
-
- // If necessary trims the text of a tooltip to ensure we don't try to display
- // a mega-tooltip.
- static void TrimTooltipText(base::string16* text);
+ virtual int GetMaxWidth(const gfx::Point& location,
+ gfx::NativeView context) const = 0;
// Returns the font list used for tooltips.
virtual const gfx::FontList& GetFontList() const = 0;
diff --git a/ui/views/widget/tooltip_manager_aura.cc b/ui/views/widget/tooltip_manager_aura.cc
index bb4ead6..8f22401 100644
--- a/ui/views/widget/tooltip_manager_aura.cc
+++ b/ui/views/widget/tooltip_manager_aura.cc
@@ -81,6 +81,12 @@ const gfx::FontList& TooltipManagerAura::GetFontList() const {
return GetDefaultFontList();
}
+int TooltipManagerAura::GetMaxWidth(const gfx::Point& point,
+ aura::Window* context) const {
+ return aura::client::GetTooltipClient(context->GetRootWindow())->
+ GetMaxWidth(point, context);
+}
+
void TooltipManagerAura::UpdateTooltip() {
aura::Window* root_window = GetWindow()->GetRootWindow();
if (aura::client::GetTooltipClient(root_window)) {
diff --git a/ui/views/widget/tooltip_manager_aura.h b/ui/views/widget/tooltip_manager_aura.h
index a7ac414..87c0f4e 100644
--- a/ui/views/widget/tooltip_manager_aura.h
+++ b/ui/views/widget/tooltip_manager_aura.h
@@ -38,6 +38,8 @@ class TooltipManagerAura : public TooltipManager {
static const gfx::FontList& GetDefaultFontList();
// TooltipManager:
+ int GetMaxWidth(const gfx::Point& location,
+ aura::Window* context) const override;
const gfx::FontList& GetFontList() const override;
void UpdateTooltip() override;
void TooltipTextChanged(View* view) override;
diff --git a/ui/wm/public/tooltip_client.h b/ui/wm/public/tooltip_client.h
index f2b97cd..f58a63e 100644
--- a/ui/wm/public/tooltip_client.h
+++ b/ui/wm/public/tooltip_client.h
@@ -8,6 +8,10 @@
#include "ui/aura/aura_export.h"
#include "ui/gfx/font.h"
+namespace gfx {
+class Point;
+}
+
namespace aura {
class Window;
namespace client {
@@ -16,6 +20,10 @@ class ScopedTooltipDisabler;
class AURA_EXPORT TooltipClient {
public:
+ // Returns the max width of the tooltip when shown at the specified location.
+ virtual int GetMaxWidth(const gfx::Point& point,
+ aura::Window* context) const = 0;
+
// Informs the shell tooltip manager of change in tooltip for window |target|.
virtual void UpdateTooltip(Window* target) = 0;