summaryrefslogtreecommitdiffstats
path: root/ui/views/widget
diff options
context:
space:
mode:
authorvarunjain@chromium.org <varunjain@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-01 21:21:11 +0000
committervarunjain@chromium.org <varunjain@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-01 21:21:11 +0000
commit4a229e90405f2c1d97409343f2c274f384284353 (patch)
treee98220c0de513a06c72207ca12dadcd3689f641c /ui/views/widget
parent084262c6432c7f673f8342326e144660b40cb7d7 (diff)
downloadchromium_src-4a229e90405f2c1d97409343f2c274f384284353.zip
chromium_src-4a229e90405f2c1d97409343f2c274f384284353.tar.gz
chromium_src-4a229e90405f2c1d97409343f2c274f384284353.tar.bz2
Reland change for aura tooltips that was revert due to build break:
http://codereview.chromium.org/8747022 BUG=97249 TEST=none Review URL: http://codereview.chromium.org/8769011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@112535 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/views/widget')
-rw-r--r--ui/views/widget/native_widget_aura.cc13
-rw-r--r--ui/views/widget/native_widget_aura.h4
-rw-r--r--ui/views/widget/tooltip_manager_aura.cc107
-rw-r--r--ui/views/widget/tooltip_manager_aura.h42
-rw-r--r--ui/views/widget/tooltip_manager_views.cc239
-rw-r--r--ui/views/widget/tooltip_manager_views.h80
6 files changed, 156 insertions, 329 deletions
diff --git a/ui/views/widget/native_widget_aura.cc b/ui/views/widget/native_widget_aura.cc
index bcb14a7..8308a45 100644
--- a/ui/views/widget/native_widget_aura.cc
+++ b/ui/views/widget/native_widget_aura.cc
@@ -22,7 +22,8 @@
#include "ui/gfx/screen.h"
#include "ui/views/widget/drop_helper.h"
#include "ui/views/widget/native_widget_delegate.h"
-#include "ui/views/widget/tooltip_manager_views.h"
+#include "ui/views/widget/tooltip_manager_aura.h"
+#include "ui/views/widget/widget_delegate.h"
#if defined(OS_WIN)
#include "base/win/scoped_gdi_object.h"
@@ -156,10 +157,8 @@ void NativeWidgetAura::InitNativeWidget(const Widget::InitParams& params) {
delegate_->OnNativeWidgetSizeChanged(params.bounds.size());
can_activate_ = params.can_activate;
DCHECK(GetWidget()->GetRootView());
- if (params.type != Widget::InitParams::TYPE_TOOLTIP && !params.child) {
- views::TooltipManagerViews* manager = new views::TooltipManagerViews(
- GetWidget()->GetRootView());
- tooltip_manager_.reset(manager);
+ if (params.type != Widget::InitParams::TYPE_TOOLTIP) {
+ tooltip_manager_.reset(new views::TooltipManagerAura(this));
}
drop_helper_.reset(new DropHelper(GetWidget()->GetRootView()));
@@ -598,13 +597,11 @@ bool NativeWidgetAura::OnMouseEvent(aura::MouseEvent* event) {
DCHECK(window_->IsVisible());
if (event->type() == ui::ET_MOUSEWHEEL) {
MouseWheelEvent wheel_event(event);
- if (tooltip_manager_.get())
- tooltip_manager_->UpdateForMouseEvent(wheel_event);
return delegate_->OnMouseEvent(wheel_event);
}
MouseEvent mouse_event(event);
if (tooltip_manager_.get())
- tooltip_manager_->UpdateForMouseEvent(mouse_event);
+ tooltip_manager_->UpdateTooltip();
return delegate_->OnMouseEvent(mouse_event);
}
diff --git a/ui/views/widget/native_widget_aura.h b/ui/views/widget/native_widget_aura.h
index a911fec..16c1bef 100644
--- a/ui/views/widget/native_widget_aura.h
+++ b/ui/views/widget/native_widget_aura.h
@@ -24,7 +24,7 @@ class Font;
namespace views {
class DropHelper;
-class TooltipManagerViews;
+class TooltipManagerAura;
class VIEWS_EXPORT NativeWidgetAura : public internal::NativeWidgetPrivate,
public aura::WindowDelegate,
@@ -168,7 +168,7 @@ class VIEWS_EXPORT NativeWidgetAura : public internal::NativeWidgetPrivate,
gfx::NativeCursor cursor_;
- scoped_ptr<TooltipManagerViews> tooltip_manager_;
+ scoped_ptr<TooltipManagerAura> tooltip_manager_;
scoped_ptr<DesktopObserverImpl> desktop_observer_;
diff --git a/ui/views/widget/tooltip_manager_aura.cc b/ui/views/widget/tooltip_manager_aura.cc
new file mode 100644
index 0000000..0847ed3
--- /dev/null
+++ b/ui/views/widget/tooltip_manager_aura.cc
@@ -0,0 +1,107 @@
+// Copyright (c) 2011 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 "base/logging.h"
+#include "ui/aura/client/aura_constants.h"
+#include "ui/aura/client/tooltip_client.h"
+#include "ui/aura/desktop.h"
+#include "ui/base/resource/resource_bundle.h"
+#include "ui/gfx/font.h"
+#include "ui/gfx/rect.h"
+#include "ui/gfx/screen.h"
+#include "ui/views/widget/native_widget_aura.h"
+#include "ui/views/widget/tooltip_manager_aura.h"
+
+namespace views {
+
+// static
+int TooltipManager::GetTooltipHeight() {
+ // Not used for linux and chromeos.
+ NOTIMPLEMENTED();
+ return 0;
+}
+
+// static
+gfx::Font TooltipManager::GetDefaultFont() {
+ return aura::TooltipClient::GetDefaultFont();
+}
+
+// static
+int TooltipManager::GetMaxWidth(int x, int y) {
+ return aura::TooltipClient::GetMaxWidth(x, y);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// TooltipManagerAura public:
+
+TooltipManagerAura::TooltipManagerAura(NativeWidgetAura* native_widget_aura)
+ : native_widget_aura_(native_widget_aura) {
+ native_widget_aura_->GetNativeView()->SetProperty(aura::kTooltipTextKey,
+ &tooltip_text_);
+}
+
+TooltipManagerAura::~TooltipManagerAura() {
+ native_widget_aura_->GetNativeView()->SetProperty(aura::kTooltipTextKey,
+ NULL);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// TooltipManagerAura, TooltipManager implementation:
+
+void TooltipManagerAura::UpdateTooltip() {
+ void* property = aura::Desktop::GetInstance()->GetProperty(
+ aura::kDesktopTooltipClientKey);
+ if (property) {
+ gfx::Point view_point = aura::Desktop::GetInstance()->last_mouse_location();
+ aura::Window::ConvertPointToWindow(aura::Desktop::GetInstance(),
+ native_widget_aura_->GetNativeView(), &view_point);
+ View* view = GetViewUnderPoint(view_point);
+ if (view) {
+ View::ConvertPointFromWidget(view, &view_point);
+ if (!view->GetTooltipText(view_point, &tooltip_text_))
+ tooltip_text_.clear();
+ } else {
+ tooltip_text_.clear();
+ }
+ aura::TooltipClient* tc = static_cast<aura::TooltipClient*>(property);
+ tc->UpdateTooltip(native_widget_aura_->GetNativeView());
+ }
+}
+
+void TooltipManagerAura::TooltipTextChanged(View* view) {
+ void* property = aura::Desktop::GetInstance()->GetProperty(
+ aura::kDesktopTooltipClientKey);
+ if (property) {
+ gfx::Point view_point = aura::Desktop::GetInstance()->last_mouse_location();
+ aura::Window::ConvertPointToWindow(aura::Desktop::GetInstance(),
+ native_widget_aura_->GetNativeView(), &view_point);
+ View* target = GetViewUnderPoint(view_point);
+ if (target != view)
+ return;
+ if (target) {
+ View::ConvertPointFromWidget(view, &view_point);
+ if (!view->GetTooltipText(view_point, &tooltip_text_))
+ tooltip_text_.clear();
+ } else {
+ tooltip_text_.clear();
+ }
+ aura::TooltipClient* tc = static_cast<aura::TooltipClient*>(property);
+ tc->UpdateTooltip(native_widget_aura_->GetNativeView());
+ }
+}
+
+void TooltipManagerAura::ShowKeyboardTooltip(View* view) {
+ NOTREACHED();
+}
+
+void TooltipManagerAura::HideKeyboardTooltip() {
+ NOTREACHED();
+}
+
+View* TooltipManagerAura::GetViewUnderPoint(const gfx::Point& point) {
+ View* root_view = native_widget_aura_->GetWidget()->GetRootView();
+ return root_view->GetEventHandlerForPoint(point);
+}
+
+} // namespace views.
diff --git a/ui/views/widget/tooltip_manager_aura.h b/ui/views/widget/tooltip_manager_aura.h
new file mode 100644
index 0000000..0ee7d6e
--- /dev/null
+++ b/ui/views/widget/tooltip_manager_aura.h
@@ -0,0 +1,42 @@
+// Copyright (c) 2011 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 UI_VIEWS_WIDGET_TOOLTIP_MANAGER_AURA_H_
+#define UI_VIEWS_WIDGET_TOOLTIP_MANAGER_AURA_H_
+#pragma once
+
+#include "base/compiler_specific.h"
+#include "base/string16.h"
+#include "ui/gfx/point.h"
+#include "ui/views/widget/tooltip_manager.h"
+
+namespace views {
+
+class NativeWidgetAura;
+class View;
+
+// TooltipManager implementation for Aura.
+class TooltipManagerAura : public TooltipManager {
+ public:
+ explicit TooltipManagerAura(NativeWidgetAura* native_widget_aura);
+ virtual ~TooltipManagerAura();
+
+ // TooltipManager.
+ virtual void UpdateTooltip() OVERRIDE;
+ virtual void TooltipTextChanged(View* view) OVERRIDE;
+ virtual void ShowKeyboardTooltip(View* view) OVERRIDE;
+ virtual void HideKeyboardTooltip() OVERRIDE;
+
+ private:
+ View* GetViewUnderPoint(const gfx::Point& point);
+
+ NativeWidgetAura* native_widget_aura_;
+ string16 tooltip_text_;
+
+ DISALLOW_COPY_AND_ASSIGN(TooltipManagerAura);
+};
+
+} // namespace views
+
+#endif // UI_VIEWS_WIDGET_TOOLTIP_MANAGER_AURA_H_
diff --git a/ui/views/widget/tooltip_manager_views.cc b/ui/views/widget/tooltip_manager_views.cc
deleted file mode 100644
index 3b2d677..0000000
--- a/ui/views/widget/tooltip_manager_views.cc
+++ /dev/null
@@ -1,239 +0,0 @@
-// Copyright (c) 2011 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 "ui/views/widget/tooltip_manager_views.h"
-
-#if defined(USE_X11)
-#include <X11/Xlib.h>
-#include <X11/extensions/XInput2.h>
-#endif
-
-#if defined(OS_WIN)
-#include <windowsx.h>
-#endif
-
-#include "base/event_types.h"
-#include "base/logging.h"
-#include "base/time.h"
-#include "base/utf_string_conversions.h"
-#include "third_party/skia/include/core/SkColor.h"
-#if defined(USE_AURA)
-#include "ui/aura/client/aura_constants.h"
-#include "ui/aura/event.h"
-#include "ui/aura/window.h"
-#endif
-#include "ui/base/resource/resource_bundle.h"
-#include "ui/gfx/font.h"
-#include "ui/gfx/screen.h"
-#include "ui/views/background.h"
-#include "ui/views/border.h"
-#include "ui/views/events/event.h"
-#include "ui/views/focus/focus_manager.h"
-#include "ui/views/view.h"
-#include "ui/views/widget/native_widget.h"
-
-namespace {
-SkColor kTooltipBackground = 0xFF7F7F00;
-int kTooltipTimeoutMs = 500;
-
-// FIXME: get cursor offset from actual cursor size.
-int kCursorOffsetX = 10;
-int kCursorOffsetY = 15;
-}
-
-namespace views {
-
-// static
-int TooltipManager::GetTooltipHeight() {
- // Not used for linux and chromeos.
- NOTREACHED();
- return 0;
-}
-
-// static
-gfx::Font TooltipManager::GetDefaultFont() {
- return ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont);
-}
-
-// static
-int TooltipManager::GetMaxWidth(int x, int y) {
- // FIXME: change this. This is for now just copied from TooltipManagerGtk.
-
- // We always display the tooltip inside the root view. So the max width is
- // the width of the view.
- gfx::Rect monitor_bounds =
- gfx::Screen::GetMonitorAreaNearestPoint(gfx::Point(x, y));
- // GtkLabel (gtk_label_ensure_layout) forces wrapping at this size. We mirror
- // the size here otherwise tooltips wider than the size used by gtklabel end
- // up with extraneous empty lines.
- return monitor_bounds.width() == 0 ? 800 : (monitor_bounds.width() + 1) / 2;
-}
-
-TooltipManagerViews::TooltipManagerViews(views::View* root_view)
- : root_view_(root_view),
- tooltip_view_(NULL) {
- tooltip_label_.set_background(
- views::Background::CreateSolidBackground(kTooltipBackground));
- tooltip_widget_.reset(CreateTooltip());
- tooltip_widget_->SetContentsView(&tooltip_label_);
- tooltip_widget_->Activate();
- tooltip_widget_->SetAlwaysOnTop(true);
-}
-
-TooltipManagerViews::~TooltipManagerViews() {
- tooltip_widget_->CloseNow();
-}
-
-void TooltipManagerViews::UpdateForMouseEvent(const MouseEvent& event) {
- switch (event.type()) {
- case ui::ET_MOUSE_EXITED:
- // Mouse is exiting this widget. Stop showing the tooltip and the timer.
- if (tooltip_timer_.IsRunning())
- tooltip_timer_.Stop();
- if (tooltip_widget_->IsVisible())
- tooltip_widget_->Hide();
- break;
- case ui::ET_MOUSE_ENTERED:
- // Mouse just entered this widget. Start the timer to show the tooltip.
- if (tooltip_timer_.IsRunning())
- tooltip_timer_.Stop();
- tooltip_timer_.Start(FROM_HERE,
- base::TimeDelta::FromMilliseconds(kTooltipTimeoutMs),
- this, &TooltipManagerViews::TooltipTimerFired);
- break;
- case ui::ET_MOUSE_MOVED:
- OnMouseMoved(event.location().x(), event.location().y());
- break;
- case ui::ET_MOUSE_PRESSED:
- case ui::ET_MOUSE_RELEASED:
- case ui::ET_MOUSE_DRAGGED:
- case ui::ET_MOUSEWHEEL:
- // Hide the tooltip for click, release, drag, wheel events.
- if (tooltip_widget_->IsVisible())
- tooltip_widget_->Hide();
- break;
- default:
- NOTIMPLEMENTED();
- }
-}
-
-void TooltipManagerViews::UpdateTooltip() {
- UpdateIfRequired(curr_mouse_pos_.x(), curr_mouse_pos_.y(), false);
-}
-
-void TooltipManagerViews::TooltipTextChanged(View* view) {
- if (tooltip_widget_->IsVisible())
- UpdateIfRequired(curr_mouse_pos_.x(), curr_mouse_pos_.y(), false);
-}
-
-void TooltipManagerViews::ShowKeyboardTooltip(View* view) {
- NOTREACHED();
-}
-
-void TooltipManagerViews::HideKeyboardTooltip() {
- NOTREACHED();
-}
-
-void TooltipManagerViews::TooltipTimerFired() {
- UpdateIfRequired(curr_mouse_pos_.x(), curr_mouse_pos_.y(), false);
-}
-
-View* TooltipManagerViews::GetViewForTooltip(int x, int y, bool for_keyboard) {
- View* view = NULL;
- if (!for_keyboard) {
- // Convert x,y from screen coordinates to |root_view_| coordinates.
- gfx::Point point(x, y);
- View::ConvertPointFromWidget(root_view_, &point);
- view = root_view_->GetEventHandlerForPoint(point);
- } else {
- FocusManager* focus_manager = root_view_->GetFocusManager();
- if (focus_manager)
- view = focus_manager->GetFocusedView();
- }
- return view;
-}
-
-void TooltipManagerViews::UpdateIfRequired(int x, int y, bool for_keyboard) {
- View* view = GetViewForTooltip(x, y, for_keyboard);
- string16 tooltip_text;
- if (view)
- view->GetTooltipText(gfx::Point(x, y), &tooltip_text);
-
-#if defined(USE_AURA)
- // In aura, and aura::Window can also have a tooltip. If the view doesnot have
- // a tooltip, we must also check for the aura::Window underneath the cursor.
- if (tooltip_text.empty()) {
- aura::Window* root = reinterpret_cast<aura::Window*>(
- root_view_->GetWidget()->GetNativeView());
- if (root) {
- aura::Window* window = root->GetEventHandlerForPoint(gfx::Point(x, y));
- if (window) {
- void* property = window->GetProperty(aura::kTooltipTextKey);
- if (property)
- tooltip_text = *reinterpret_cast<string16*>(property);
- }
- }
- }
-#endif
-
- if (tooltip_view_ != view || tooltip_text_ != tooltip_text) {
- tooltip_view_ = view;
- tooltip_text_ = tooltip_text;
- Update();
- }
-}
-
-void TooltipManagerViews::Update() {
- if (tooltip_text_.empty()) {
- tooltip_widget_->Hide();
- } else {
- int max_width, line_count;
- string16 tooltip_text(tooltip_text_);
- TrimTooltipToFit(&tooltip_text, &max_width, &line_count,
- curr_mouse_pos_.x(), curr_mouse_pos_.y());
- tooltip_label_.SetText(tooltip_text);
-
- SetTooltipBounds(curr_mouse_pos_, max_width,
- tooltip_label_.GetPreferredSize().height());
- tooltip_widget_->Show();
- }
-}
-
-void TooltipManagerViews::SetTooltipBounds(gfx::Point mouse_pos,
- int tooltip_width,
- int tooltip_height) {
- gfx::Rect tooltip_rect(mouse_pos.x(), mouse_pos.y(), tooltip_width,
- tooltip_height);
-
- tooltip_rect.Offset(kCursorOffsetX, kCursorOffsetY);
- gfx::Rect monitor_bounds =
- gfx::Screen::GetMonitorAreaNearestPoint(tooltip_rect.origin());
- tooltip_widget_->SetBounds(tooltip_rect.AdjustToFit(monitor_bounds));
-}
-
-Widget* TooltipManagerViews::CreateTooltip() {
- Widget* widget = new Widget;
- Widget::InitParams params;
- // For aura, since we set the type to TOOLTIP_TYPE, the widget will get
- // auto-parented to the MenuAndTooltipsContainer.
- params.type = Widget::InitParams::TYPE_TOOLTIP;
- params.keep_on_top = true;
- params.accept_events = false;
- params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
- widget->Init(params);
- widget->SetOpacity(0xFF);
- return widget;
-}
-
-void TooltipManagerViews::OnMouseMoved(int x, int y) {
- if (tooltip_timer_.IsRunning())
- tooltip_timer_.Reset();
- curr_mouse_pos_.SetPoint(x, y);
-
- // If tooltip is visible, we may want to hide it. If it is not, we are ok.
- if (tooltip_widget_->IsVisible())
- UpdateIfRequired(curr_mouse_pos_.x(), curr_mouse_pos_.y(), false);
-}
-
-} // namespace views
diff --git a/ui/views/widget/tooltip_manager_views.h b/ui/views/widget/tooltip_manager_views.h
deleted file mode 100644
index 1a6ef18..0000000
--- a/ui/views/widget/tooltip_manager_views.h
+++ /dev/null
@@ -1,80 +0,0 @@
-// Copyright (c) 2011 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 UI_VIEWS_WIDGET_TOOLTIP_MANAGER_VIEWS_H_
-#define UI_VIEWS_WIDGET_TOOLTIP_MANAGER_VIEWS_H_
-#pragma once
-
-#include "base/message_loop.h"
-#include "base/timer.h"
-#include "ui/views/controls/label.h"
-#include "ui/views/view.h"
-#include "ui/views/widget/native_widget.h"
-#include "ui/views/widget/tooltip_manager.h"
-#include "ui/views/widget/widget_delegate.h"
-
-#if defined(USE_X11)
-typedef union _XEvent XEvent;
-#endif
-
-namespace views {
-
-class MouseEvent;
-class Widget;
-
-// TooltipManager implementation for Views.
-class TooltipManagerViews : public TooltipManager {
- public:
- explicit TooltipManagerViews(views::View* root_view);
- virtual ~TooltipManagerViews();
-
- // Updates the state of the tooltip based on the mouse event. The mouse event
- // is the same event that goes to a Widget (i.e. it is in the Widget's
- // coordinate system).
- void UpdateForMouseEvent(const MouseEvent& event);
-
- // TooltipManager.
- virtual void UpdateTooltip() OVERRIDE;
- virtual void TooltipTextChanged(View* view) OVERRIDE;
- virtual void ShowKeyboardTooltip(View* view) OVERRIDE;
- virtual void HideKeyboardTooltip() OVERRIDE;
-
- private:
- void TooltipTimerFired();
- View* GetViewForTooltip(int x, int y, bool for_keyboard);
-
- // Updates the tooltip if required (if there is any change in the tooltip
- // text or the view.
- void UpdateIfRequired(int x, int y, bool for_keyboard);
-
- // Updates the tooltip. Gets the tooltip text from tooltip_view_ and displays
- // it at the current mouse position.
- void Update();
-
- // Adjusts the bounds given by the arguments to fit inside the parent view
- // and applies the adjusted bounds to the tooltip_label_.
- void SetTooltipBounds(gfx::Point mouse_pos, int tooltip_width,
- int tooltip_height);
-
- // Creates a widget of type TYPE_TOOLTIP
- Widget* CreateTooltip();
-
- // Invoked when the mose moves.
- void OnMouseMoved(int x, int y);
-
- scoped_ptr<Widget> tooltip_widget_;
- views::View* root_view_;
- View* tooltip_view_;
- string16 tooltip_text_;
- Label tooltip_label_;
-
- gfx::Point curr_mouse_pos_;
- base::RepeatingTimer<TooltipManagerViews> tooltip_timer_;
-
- DISALLOW_COPY_AND_ASSIGN(TooltipManagerViews);
-};
-
-} // namespace views
-
-#endif // UI_VIEWS_WIDGET_TOOLTIP_MANAGER_VIEWS_H_