Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(91)

Unified Diff: ui/views/cocoa/bridged_content_view.mm

Issue 1137653005: MacViews: Implement Tooltips (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: respond to comments Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/cocoa/bridged_content_view.h ('k') | ui/views/cocoa/bridged_native_widget.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/cocoa/bridged_content_view.mm
diff --git a/ui/views/cocoa/bridged_content_view.mm b/ui/views/cocoa/bridged_content_view.mm
index 266a6f13b9200f889fee08d42d4346122d1880fb..fa0731c8ae3ffcbc017d794080f911c56297c6d2 100644
--- a/ui/views/cocoa/bridged_content_view.mm
+++ b/ui/views/cocoa/bridged_content_view.mm
@@ -58,10 +58,6 @@ bool DispatchEventToMenu(views::Widget* widget, ui::KeyboardCode key_code) {
@interface BridgedContentView ()
-// Translates the location of |theEvent| to toolkit-views coordinates and passes
-// the event to NativeWidgetMac for handling.
-- (void)handleMouseEvent:(NSEvent*)theEvent;
-
// Translates keycodes and modifiers on |theEvent| to ui::KeyEvents and passes
// the event to the InputMethod for dispatch.
- (void)handleKeyEvent:(NSEvent*)theEvent;
@@ -110,21 +106,21 @@ bool DispatchEventToMenu(views::Widget* widget, ui::KeyboardCode key_code) {
// Apple's documentation says that NSTrackingActiveAlways is incompatible
// with NSTrackingCursorUpdate, so use NSTrackingActiveInActiveApp.
- trackingArea_.reset([[CrTrackingArea alloc]
+ cursorTrackingArea_.reset([[CrTrackingArea alloc]
initWithRect:NSZeroRect
options:NSTrackingMouseMoved | NSTrackingCursorUpdate |
NSTrackingActiveInActiveApp | NSTrackingInVisibleRect
owner:self
userInfo:nil]);
- [self addTrackingArea:trackingArea_.get()];
+ [self addTrackingArea:cursorTrackingArea_.get()];
}
return self;
}
- (void)clearView {
hostedView_ = NULL;
- [trackingArea_.get() clearOwner];
- [self removeTrackingArea:trackingArea_.get()];
+ [cursorTrackingArea_.get() clearOwner];
+ [self removeTrackingArea:cursorTrackingArea_.get()];
}
- (void)processCapturedMouseEvent:(NSEvent*)theEvent {
@@ -137,7 +133,7 @@ bool DispatchEventToMenu(views::Widget* widget, ui::KeyboardCode key_code) {
// If it's the view's window, process normally.
if ([target isEqual:source]) {
- [self handleMouseEvent:theEvent];
+ [self mouseEvent:theEvent];
return;
}
@@ -147,16 +143,25 @@ bool DispatchEventToMenu(views::Widget* widget, ui::KeyboardCode key_code) {
hostedView_->GetWidget()->OnMouseEvent(&event);
}
-// BridgedContentView private implementation.
-
-- (void)handleMouseEvent:(NSEvent*)theEvent {
- if (!hostedView_)
- return;
+- (void)updateTooltipIfRequiredAt:(const gfx::Point&)locationInContent {
+ DCHECK(hostedView_);
+ base::string16 newTooltipText;
- ui::MouseEvent event(theEvent);
- hostedView_->GetWidget()->OnMouseEvent(&event);
+ views::View* view = hostedView_->GetTooltipHandlerForPoint(locationInContent);
+ if (view) {
+ gfx::Point viewPoint = locationInContent;
+ views::View::ConvertPointToTarget(hostedView_, view, &viewPoint);
+ if (!view->GetTooltipText(viewPoint, &newTooltipText))
+ DCHECK(newTooltipText.empty());
+ }
+ if (newTooltipText != lastTooltipText_) {
+ std::swap(newTooltipText, lastTooltipText_);
+ [self setToolTipAtMousePoint:base::SysUTF16ToNSString(lastTooltipText_)];
+ }
}
+// BridgedContentView private implementation.
+
- (void)handleKeyEvent:(NSEvent*)theEvent {
if (!hostedView_)
return;
@@ -243,6 +248,28 @@ bool DispatchEventToMenu(views::Widget* widget, ui::KeyboardCode key_code) {
eventFlags:ui::EF_CONTROL_DOWN];
}
+// BaseView implementation.
+
+// Don't use tracking areas from BaseView. BridgedContentView's tracks
+// NSTrackingCursorUpdate and Apple's documentation suggests it's incompatible.
+- (void)enableTracking {
+}
+
+// Translates the location of |theEvent| to toolkit-views coordinates and passes
+// the event to NativeWidgetMac for handling.
+- (void)mouseEvent:(NSEvent*)theEvent {
+ if (!hostedView_)
+ return;
+
+ ui::MouseEvent event(theEvent);
+
+ // Aura updates tooltips with the help of aura::Window::AddPreTargetHandler().
+ // Mac hooks in here.
+ [self updateTooltipIfRequiredAt:event.location()];
+
+ hostedView_->GetWidget()->OnMouseEvent(&event);
+}
+
// NSView implementation.
- (BOOL)acceptsFirstResponder {
@@ -311,49 +338,6 @@ bool DispatchEventToMenu(views::Widget* widget, ui::KeyboardCode key_code) {
inKeyDown_ = NO;
}
-- (void)mouseDown:(NSEvent*)theEvent {
- [self handleMouseEvent:theEvent];
-}
-
-- (void)rightMouseDown:(NSEvent*)theEvent {
- [self handleMouseEvent:theEvent];
-}
-
-- (void)otherMouseDown:(NSEvent*)theEvent {
- [self handleMouseEvent:theEvent];
-}
-
-- (void)mouseUp:(NSEvent*)theEvent {
- [self handleMouseEvent:theEvent];
-}
-
-- (void)rightMouseUp:(NSEvent*)theEvent {
- [self handleMouseEvent:theEvent];
-}
-
-- (void)otherMouseUp:(NSEvent*)theEvent {
- [self handleMouseEvent:theEvent];
-}
-
-- (void)mouseDragged:(NSEvent*)theEvent {
- [self handleMouseEvent:theEvent];
-}
-
-- (void)rightMouseDragged:(NSEvent*)theEvent {
- [self handleMouseEvent:theEvent];
-}
-
-- (void)otherMouseDragged:(NSEvent*)theEvent {
- [self handleMouseEvent:theEvent];
-}
-
-- (void)mouseMoved:(NSEvent*)theEvent {
- // Note: mouseEntered: and mouseExited: are not handled separately.
- // |hostedView_| is responsible for converting the move events into entered
- // and exited events for the view heirarchy.
- [self handleMouseEvent:theEvent];
-}
-
- (void)scrollWheel:(NSEvent*)theEvent {
if (!hostedView_)
return;
« no previous file with comments | « ui/views/cocoa/bridged_content_view.h ('k') | ui/views/cocoa/bridged_native_widget.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698