| 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 e29ea9ec01c90fadc6ff333da92cdd99d04b00e4..93258bb5924e655220a54f3be298f18c53d0c23f 100644
|
| --- a/ui/views/cocoa/bridged_content_view.mm
|
| +++ b/ui/views/cocoa/bridged_content_view.mm
|
| @@ -7,6 +7,7 @@
|
| #include "base/logging.h"
|
| #import "base/mac/mac_util.h"
|
| #import "base/mac/scoped_nsobject.h"
|
| +#import "base/mac/sdk_forward_declarations.h"
|
| #include "base/strings/sys_string_conversions.h"
|
| #include "skia/ext/skia_utils_mac.h"
|
| #include "ui/base/cocoa/cocoa_base_utils.h"
|
| @@ -17,13 +18,16 @@
|
| #include "ui/base/ime/text_input_client.h"
|
| #include "ui/compositor/canvas_painter.h"
|
| #import "ui/events/cocoa/cocoa_event_utils.h"
|
| +#include "ui/events/event_utils.h"
|
| #include "ui/events/keycodes/dom/dom_code.h"
|
| #import "ui/events/keycodes/keyboard_code_conversion_mac.h"
|
| #include "ui/gfx/canvas_paint_mac.h"
|
| +#include "ui/gfx/decorated_text.h"
|
| #include "ui/gfx/geometry/rect.h"
|
| #import "ui/gfx/mac/coordinate_conversion.h"
|
| #include "ui/gfx/path.h"
|
| #import "ui/gfx/path_mac.h"
|
| +#include "ui/gfx/render_text.h"
|
| #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h"
|
| #import "ui/views/cocoa/bridged_native_widget.h"
|
| #import "ui/views/cocoa/drag_drop_client_mac.h"
|
| @@ -207,6 +211,43 @@ bool IsTextRTL(const ui::TextInputClient* client) {
|
| ui::KeyboardCodeFromNSEvent(event), ui::EF_NONE);
|
| }
|
|
|
| +NSAttributedString* GetAttributedString(
|
| + const gfx::DecoratedText& decorated_text) {
|
| + base::scoped_nsobject<NSMutableAttributedString> str(
|
| + [[NSMutableAttributedString alloc] init]);
|
| + [str beginEditing];
|
| + [[str mutableString] setString:base::SysUTF16ToNSString(decorated_text.text)];
|
| +
|
| + for (const auto& attribute : decorated_text.attributes) {
|
| + DCHECK(!attribute.range.is_reversed());
|
| + DCHECK_LE(attribute.range.end(), [str length]);
|
| +
|
| + NSMutableDictionary* attrs = [NSMutableDictionary dictionary];
|
| + NSRange range = attribute.range.ToNSRange();
|
| +
|
| + if (attribute.font.GetNativeFont())
|
| + attrs[NSFontAttributeName] = attribute.font.GetNativeFont();
|
| +
|
| + // NSFont does not have underline as an attribute. Hence handle it
|
| + // separately.
|
| + const bool underline = attribute.font.GetStyle() & gfx::Font::UNDERLINE;
|
| + if (underline) {
|
| + attrs[NSUnderlineStyleAttributeName] =
|
| + @(NSUnderlineStyleSingle | NSUnderlinePatternSolid);
|
| + }
|
| +
|
| + if (attribute.strike) {
|
| + attrs[NSStrikethroughStyleAttributeName] =
|
| + @(NSUnderlineStyleSingle | NSUnderlinePatternSolid);
|
| + }
|
| +
|
| + [str setAttributes:attrs range:range];
|
| + }
|
| +
|
| + [str endEditing];
|
| + return str.autorelease();
|
| +}
|
| +
|
| } // namespace
|
|
|
| @interface BridgedContentView ()
|
| @@ -740,6 +781,36 @@ - (void)scrollWheel:(NSEvent*)theEvent {
|
| hostedView_->GetWidget()->OnScrollEvent(&event);
|
| }
|
|
|
| +- (void)quickLookWithEvent:(NSEvent*)theEvent {
|
| + if (!hostedView_)
|
| + return;
|
| +
|
| + const gfx::Point locationInContent = ui::EventLocationFromNative(theEvent);
|
| + views::View* target = hostedView_->GetEventHandlerForPoint(locationInContent);
|
| + if (!target)
|
| + return;
|
| +
|
| + gfx::RenderText* renderText = target->GetRenderText();
|
| + if (!renderText)
|
| + return;
|
| +
|
| + gfx::Point locationInTarget = locationInContent;
|
| + views::View::ConvertPointToTarget(hostedView_, target, &locationInTarget);
|
| + gfx::DecoratedText decorated_word;
|
| + gfx::Point baselinePoint;
|
| + if (!renderText->GetDecoratedWordAtPoint(locationInTarget, &decorated_word,
|
| + &baselinePoint)) {
|
| + return;
|
| + }
|
| +
|
| + // Convert |baselinePoint| to the coordinate system of |hostedView_|.
|
| + views::View::ConvertPointToTarget(target, hostedView_, &baselinePoint);
|
| + NSPoint baselinePointAppKit = NSMakePoint(
|
| + baselinePoint.x(), NSHeight([self frame]) - baselinePoint.y());
|
| + [self showDefinitionForAttributedString:GetAttributedString(decorated_word)
|
| + atPoint:baselinePointAppKit];
|
| +}
|
| +
|
| ////////////////////////////////////////////////////////////////////////////////
|
| // NSResponder Action Messages. Keep sorted according NSResponder.h (from the
|
| // 10.9 SDK). The list should eventually be complete. Anything not defined will
|
|
|