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

Unified Diff: content/browser/renderer_host/render_widget_host_view_mac.mm

Issue 10830176: [Mac]: Make dictionary context menu item use system settings for whether to launch Dictionary.app o… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 4 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
Index: content/browser/renderer_host/render_widget_host_view_mac.mm
===================================================================
--- content/browser/renderer_host/render_widget_host_view_mac.mm (revision 149502)
+++ content/browser/renderer_host/render_widget_host_view_mac.mm (working copy)
@@ -140,6 +140,8 @@
- (void)windowChangedScreen:(NSNotification*)notification;
- (void)checkForPluginImeCancellation;
- (void)updateTabBackingStoreScaleFactor;
+- (NSRect)firstViewRectForCharacterRange:(NSRange)theRange
+ actualRange:(NSRangePointer)actualRange;
@end
// NSEvent subtype for scroll gestures events.
@@ -754,7 +756,7 @@
size_t offset,
const ui::Range& range) {
if (range.is_empty() || text.empty()) {
- selected_text_.clear();
+ selected_text_.clear();
} else {
size_t pos = range.GetMin() - offset;
size_t n = range.length();
@@ -768,7 +770,7 @@
}
[cocoa_view_ setSelectedRange:range.ToNSRange()];
- // Updaes markedRange when there is no marked text so that retrieving
+ // Updates markedRange when there is no marked text so that retrieving
// markedRange immediately after calling setMarkdText: returns the current
// caret position.
if (![cocoa_view_ hasMarkedText]) {
@@ -1400,6 +1402,24 @@
}
}
+void RenderWidgetHostViewMac::ShowDefinitionForSelection() {
+ // Brings up either Dictionary.app or a light-weight dictionary panel,
+ // depending on system settings.
+ NSRange selection_range = [cocoa_view_ selectedRange];
+ NSAttributedString* attr_string =
+ [cocoa_view_ attributedSubstringForProposedRange:selection_range
+ actualRange:nil];
+ NSRect rect = [cocoa_view_ firstViewRectForCharacterRange:selection_range
+ actualRange:nil];
+
+ // Set |rect.origin| to the text baseline based on |attr_string|'s font.
+ NSDictionary* attrs = [attr_string attributesAtIndex:0 effectiveRange:nil];
+ NSFont* font = [attrs objectForKey:NSFontAttributeName];
+ rect.origin.y += rect.size.height - [font ascender];
Nico 2012/08/04 02:34:02 NSHeight(rect) (NSFont seems to return view units
+ [cocoa_view_ showDefinitionForAttributedString:attr_string
+ atPoint:rect.origin];
+}
+
void RenderWidgetHostViewMac::SetBackground(const SkBitmap& background) {
RenderWidgetHostViewBase::SetBackground(background);
if (render_widget_host_)
@@ -2797,8 +2817,8 @@
return index;
}
-- (NSRect)firstRectForCharacterRange:(NSRange)theRange
- actualRange:(NSRangePointer)actualRange {
+- (NSRect)firstViewRectForCharacterRange:(NSRange)theRange
+ actualRange:(NSRangePointer)actualRange {
NSRect rect;
if (!renderWidgetHostView_->GetCachedFirstRectForCharacterRange(
theRange,
@@ -2813,10 +2833,18 @@
}
// The returned rectangle is in WebKit coordinates (upper left origin), so
- // flip the coordinate system and then convert it into screen coordinates for
- // return.
+ // flip the coordinate system.
NSRect viewFrame = [self frame];
rect.origin.y = NSHeight(viewFrame) - NSMaxY(rect);
+ return rect;
+}
+
+- (NSRect)firstRectForCharacterRange:(NSRange)theRange
+ actualRange:(NSRangePointer)actualRange {
+ NSRect rect = [self firstViewRectForCharacterRange:theRange
+ actualRange:actualRange];
+
+ // Convert into screen coordinates for return.
rect = [self convertRect:rect toView:nil];
rect.origin = [[self window] convertBaseToScreen:rect.origin];
return rect;
« no previous file with comments | « content/browser/renderer_host/render_widget_host_view_mac.h ('k') | content/public/browser/render_widget_host_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698