Enable tooltips for aura.

BUG=97249
TEST=none


Review URL: http://codereview.chromium.org/8371024

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@107630 0039d316-1c4b-4281-b951-d872f2087c98
parent 582b55d4
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "content/browser/renderer_host/render_widget_host.h" #include "content/browser/renderer_host/render_widget_host.h"
#include "content/public/browser/native_web_keyboard_event.h" #include "content/public/browser/native_web_keyboard_event.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
#include "ui/aura/aura_constants.h"
#include "ui/aura/desktop.h" #include "ui/aura/desktop.h"
#include "ui/aura/event.h" #include "ui/aura/event.h"
#include "ui/aura/hit_test.h" #include "ui/aura/hit_test.h"
...@@ -219,7 +220,8 @@ void RenderWidgetHostViewAura::Destroy() { ...@@ -219,7 +220,8 @@ void RenderWidgetHostViewAura::Destroy() {
} }
void RenderWidgetHostViewAura::SetTooltipText(const string16& tooltip_text) { void RenderWidgetHostViewAura::SetTooltipText(const string16& tooltip_text) {
//NOTIMPLEMENTED(); string16* tooltip = new string16(tooltip_text);
window_->SetProperty(aura::kTooltipTextKey, tooltip);
} }
BackingStore* RenderWidgetHostViewAura::AllocBackingStore( BackingStore* RenderWidgetHostViewAura::AllocBackingStore(
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
'AURA_IMPLEMENTATION', 'AURA_IMPLEMENTATION',
], ],
'sources': [ 'sources': [
'aura_constants.h',
'aura_switches.cc', 'aura_switches.cc',
'aura_switches.h', 'aura_switches.h',
'cursor.h', 'cursor.h',
......
// 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_AURA_AURA_CONSTANTS_H_
#define UI_AURA_AURA_CONSTANTS_H_
#pragma once
#include "ui/aura/aura_export.h"
namespace aura {
AURA_EXPORT const char* kTooltipTextKey = "TooltipTextKey";
} // namespace aura
#endif // UI_AURA_AURA_CONSTANTS_H_
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "ui/gfx/font.h" #include "ui/gfx/font.h"
#include "ui/gfx/screen.h" #include "ui/gfx/screen.h"
#include "views/widget/native_widget_delegate.h" #include "views/widget/native_widget_delegate.h"
#include "views/widget/tooltip_manager_views.h"
#if defined(OS_WIN) #if defined(OS_WIN)
#include "base/win/scoped_gdi_object.h" #include "base/win/scoped_gdi_object.h"
...@@ -93,6 +94,12 @@ void NativeWidgetAura::InitNativeWidget(const Widget::InitParams& params) { ...@@ -93,6 +94,12 @@ void NativeWidgetAura::InitNativeWidget(const Widget::InitParams& params) {
// TODO(beng): do this some other way. // TODO(beng): do this some other way.
delegate_->OnNativeWidgetSizeChanged(params.bounds.size()); delegate_->OnNativeWidgetSizeChanged(params.bounds.size());
can_activate_ = params.can_activate; can_activate_ = params.can_activate;
if (params.type != Widget::InitParams::TYPE_TOOLTIP && !params.child) {
DCHECK(GetWidget()->GetRootView());
views::TooltipManagerViews* manager = new views::TooltipManagerViews(
GetWidget()->GetRootView());
tooltip_manager_.reset(manager);
}
} }
NonClientFrameView* NativeWidgetAura::CreateNonClientFrameView() { NonClientFrameView* NativeWidgetAura::CreateNonClientFrameView() {
...@@ -170,8 +177,7 @@ void* NativeWidgetAura::GetNativeWindowProperty(const char* name) const { ...@@ -170,8 +177,7 @@ void* NativeWidgetAura::GetNativeWindowProperty(const char* name) const {
} }
TooltipManager* NativeWidgetAura::GetTooltipManager() const { TooltipManager* NativeWidgetAura::GetTooltipManager() const {
//NOTIMPLEMENTED(); return tooltip_manager_.get();
return NULL;
} }
bool NativeWidgetAura::IsScreenReaderActive() const { bool NativeWidgetAura::IsScreenReaderActive() const {
......
...@@ -158,6 +158,8 @@ class VIEWS_EXPORT NativeWidgetAura : public internal::NativeWidgetPrivate, ...@@ -158,6 +158,8 @@ class VIEWS_EXPORT NativeWidgetAura : public internal::NativeWidgetPrivate,
gfx::NativeCursor cursor_; gfx::NativeCursor cursor_;
scoped_ptr<TooltipManager> tooltip_manager_;
DISALLOW_COPY_AND_ASSIGN(NativeWidgetAura); DISALLOW_COPY_AND_ASSIGN(NativeWidgetAura);
}; };
......
...@@ -17,6 +17,11 @@ ...@@ -17,6 +17,11 @@
#include "base/time.h" #include "base/time.h"
#include "base/utf_string_conversions.h" #include "base/utf_string_conversions.h"
#include "third_party/skia/include/core/SkColor.h" #include "third_party/skia/include/core/SkColor.h"
#if defined(USE_AURA)
#include "ui/aura/aura_constants.h"
#include "ui/aura/event.h"
#include "ui/aura/window.h"
#endif
#include "ui/base/resource/resource_bundle.h" #include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/font.h" #include "ui/gfx/font.h"
#include "ui/gfx/screen.h" #include "ui/gfx/screen.h"
...@@ -26,7 +31,6 @@ ...@@ -26,7 +31,6 @@
#include "views/focus/focus_manager.h" #include "views/focus/focus_manager.h"
#include "views/view.h" #include "views/view.h"
#include "views/widget/native_widget.h" #include "views/widget/native_widget.h"
#include "views/widget/root_view.h"
#if defined(USE_WAYLAND) #if defined(USE_WAYLAND)
#include "ui/wayland/events/wayland_event.h" #include "ui/wayland/events/wayland_event.h"
...@@ -69,7 +73,7 @@ int TooltipManager::GetMaxWidth(int x, int y) { ...@@ -69,7 +73,7 @@ int TooltipManager::GetMaxWidth(int x, int y) {
return monitor_bounds.width() == 0 ? 800 : (monitor_bounds.width() + 1) / 2; return monitor_bounds.width() == 0 ? 800 : (monitor_bounds.width() + 1) / 2;
} }
TooltipManagerViews::TooltipManagerViews(internal::RootView* root_view) TooltipManagerViews::TooltipManagerViews(views::View* root_view)
: root_view_(root_view), : root_view_(root_view),
tooltip_view_(NULL) { tooltip_view_(NULL) {
tooltip_label_.set_background( tooltip_label_.set_background(
...@@ -115,12 +119,19 @@ base::MessagePumpObserver::EventStatus TooltipManagerViews::WillProcessEvent( ...@@ -115,12 +119,19 @@ base::MessagePumpObserver::EventStatus TooltipManagerViews::WillProcessEvent(
} }
#elif defined(USE_X11) #elif defined(USE_X11)
base::EventStatus TooltipManagerViews::WillProcessEvent( base::EventStatus TooltipManagerViews::WillProcessEvent(
const base::NativeEvent& event) { const base::NativeEvent& native_event) {
XGenericEventCookie* cookie = &event->xcookie; if (!ui::IsMouseEvent(native_event))
if (cookie->evtype == XI_Motion) { return base::EVENT_CONTINUE;
const XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(cookie->data); #if defined(USE_AURA)
OnMouseMoved(static_cast<int>(xievent->event_x), aura::MouseEvent event(native_event);
static_cast<int>(xievent->event_y)); #else
MouseEvent event(native_event);
#endif
switch (event.type()) {
case ui::ET_MOUSE_MOVED:
OnMouseMoved(event.x(), event.y());
default:
break;
} }
return base::EVENT_CONTINUE; return base::EVENT_CONTINUE;
} }
...@@ -140,19 +151,18 @@ void TooltipManagerViews::DidProcessEvent(const base::NativeEvent& event) { ...@@ -140,19 +151,18 @@ void TooltipManagerViews::DidProcessEvent(const base::NativeEvent& event) {
#endif #endif
void TooltipManagerViews::TooltipTimerFired() { void TooltipManagerViews::TooltipTimerFired() {
if (tooltip_widget_->IsVisible()) { UpdateIfRequired(curr_mouse_pos_.x(), curr_mouse_pos_.y(), false);
UpdateIfRequired(curr_mouse_pos_.x(), curr_mouse_pos_.y(), false);
} else {
tooltip_view_ = GetViewForTooltip(curr_mouse_pos_.x(), curr_mouse_pos_.y(),
false);
Update();
}
} }
View* TooltipManagerViews::GetViewForTooltip(int x, int y, bool for_keyboard) { View* TooltipManagerViews::GetViewForTooltip(int x, int y, bool for_keyboard) {
View* view = NULL; View* view = NULL;
if (!for_keyboard) { if (!for_keyboard) {
view = root_view_->GetEventHandlerForPoint(gfx::Point(x, y)); // Convert x,y from screen coordinates to |root_view_| coordinates.
gfx::Point point(x, y);
gfx::Rect r = root_view_->GetWidget()->GetClientAreaScreenBounds();
point.SetPoint(point.x() - r.x(), point.y() - r.y());
View::ConvertPointFromWidget(root_view_, &point);
view = root_view_->GetEventHandlerForPoint(point);
} else { } else {
FocusManager* focus_manager = root_view_->GetFocusManager(); FocusManager* focus_manager = root_view_->GetFocusManager();
if (focus_manager) if (focus_manager)
...@@ -167,17 +177,31 @@ void TooltipManagerViews::UpdateIfRequired(int x, int y, bool for_keyboard) { ...@@ -167,17 +177,31 @@ void TooltipManagerViews::UpdateIfRequired(int x, int y, bool for_keyboard) {
if (view) if (view)
view->GetTooltipText(gfx::Point(x, y), &tooltip_text); 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) { if (tooltip_view_ != view || tooltip_text_ != tooltip_text) {
tooltip_view_ = view; tooltip_view_ = view;
tooltip_text_ = tooltip_text;
Update(); Update();
} }
} }
void TooltipManagerViews::Update() { void TooltipManagerViews::Update() {
if (!tooltip_view_ ||
!tooltip_view_->GetTooltipText(gfx::Point(), &tooltip_text_))
tooltip_text_.clear();
if (tooltip_text_.empty()) { if (tooltip_text_.empty()) {
tooltip_widget_->Hide(); tooltip_widget_->Hide();
} else { } else {
...@@ -196,7 +220,6 @@ void TooltipManagerViews::Update() { ...@@ -196,7 +220,6 @@ void TooltipManagerViews::Update() {
void TooltipManagerViews::SetTooltipBounds(gfx::Point mouse_pos, void TooltipManagerViews::SetTooltipBounds(gfx::Point mouse_pos,
int tooltip_width, int tooltip_width,
int tooltip_height) { int tooltip_height) {
View::ConvertPointToScreen(root_view_, &mouse_pos);
gfx::Rect tooltip_rect(mouse_pos.x(), mouse_pos.y(), tooltip_width, gfx::Rect tooltip_rect(mouse_pos.x(), mouse_pos.y(), tooltip_width,
tooltip_height); tooltip_height);
...@@ -209,12 +232,14 @@ void TooltipManagerViews::SetTooltipBounds(gfx::Point mouse_pos, ...@@ -209,12 +232,14 @@ void TooltipManagerViews::SetTooltipBounds(gfx::Point mouse_pos,
Widget* TooltipManagerViews::CreateTooltip() { Widget* TooltipManagerViews::CreateTooltip() {
Widget* widget = new Widget; Widget* widget = new Widget;
Widget::InitParams params; 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.type = Widget::InitParams::TYPE_TOOLTIP;
params.keep_on_top = true; params.keep_on_top = true;
params.accept_events = false; params.accept_events = false;
params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
widget->Init(params); widget->Init(params);
widget->SetOpacity(0x00); widget->SetOpacity(0xFF);
return widget; return widget;
} }
......
...@@ -23,17 +23,13 @@ union WaylandEvent; ...@@ -23,17 +23,13 @@ union WaylandEvent;
namespace views { namespace views {
namespace internal {
class RootView;
}
class Widget; class Widget;
// TooltipManager implementation for Views. // TooltipManager implementation for Views.
class TooltipManagerViews : public TooltipManager, class TooltipManagerViews : public TooltipManager,
public MessageLoopForUI::Observer { public MessageLoopForUI::Observer {
public: public:
explicit TooltipManagerViews(internal::RootView* root_view); explicit TooltipManagerViews(views::View* root_view);
virtual ~TooltipManagerViews(); virtual ~TooltipManagerViews();
// TooltipManager. // TooltipManager.
...@@ -76,7 +72,7 @@ class TooltipManagerViews : public TooltipManager, ...@@ -76,7 +72,7 @@ class TooltipManagerViews : public TooltipManager,
void OnMouseMoved(int x, int y); void OnMouseMoved(int x, int y);
scoped_ptr<Widget> tooltip_widget_; scoped_ptr<Widget> tooltip_widget_;
internal::RootView* root_view_; views::View* root_view_;
View* tooltip_view_; View* tooltip_view_;
string16 tooltip_text_; string16 tooltip_text_;
Label tooltip_label_; Label tooltip_label_;
......
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