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

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

Issue 2164483006: [MacViews] Implemented text context menu (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 3 years, 10 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/BUILD.gn ('k') | ui/views/controls/label.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 1796fff92a576f87b724a6acb8d6182c27da72b9..b47f522dd7c759f2f1450c06c5eb9b544bfe0806 100644
--- a/ui/views/cocoa/bridged_content_view.mm
+++ b/ui/views/cocoa/bridged_content_view.mm
@@ -24,6 +24,7 @@
#import "ui/events/keycodes/keyboard_code_conversion_mac.h"
#include "ui/gfx/canvas_paint_mac.h"
#include "ui/gfx/decorated_text.h"
+#import "ui/gfx/decorated_text_mac.h"
#include "ui/gfx/geometry/rect.h"
#import "ui/gfx/mac/coordinate_conversion.h"
#include "ui/gfx/path.h"
@@ -200,42 +201,6 @@ base::string16 AttributedSubstringForRangeHelper(
return substring;
}
-NSAttributedString* GetAttributedString(
- const gfx::DecoratedText& decorated_text) {
- base::scoped_nsobject<NSMutableAttributedString> str(
- [[NSMutableAttributedString alloc]
- initWithString:base::SysUTF16ToNSString(decorated_text.text)]);
- [str beginEditing];
-
- NSValue* const line_style =
- @(NSUnderlineStyleSingle | NSUnderlinePatternSolid);
-
- 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] = line_style;
-
- if (attribute.strike)
- attrs[NSStrikethroughStyleAttributeName] = line_style;
-
- [str setAttributes:attrs range:range];
- }
-
- [str endEditing];
- return str.autorelease();
-}
-
ui::TextEditCommand GetTextEditCommandForMenuAction(SEL action) {
if (action == @selector(undo:))
return ui::TextEditCommand::UNDO;
@@ -254,6 +219,8 @@ ui::TextEditCommand GetTextEditCommandForMenuAction(SEL action) {
} // namespace
+// TODO(spqchan): Implement support when the Speech submenu is in the main
+// menu.
@interface BridgedContentView ()
// Returns the active menu controller corresponding to |hostedView_|,
@@ -851,7 +818,7 @@ ui::TextEditCommand GetTextEditCommandForMenuAction(SEL action) {
views::View::ConvertPointToTarget(hostedView_, target, &locationInTarget);
gfx::DecoratedText decoratedWord;
gfx::Point baselinePoint;
- if (!wordLookupClient->GetDecoratedWordAtPoint(
+ if (!wordLookupClient->GetDecoratedWordAndBaselineAtPoint(
locationInTarget, &decoratedWord, &baselinePoint)) {
return;
}
@@ -860,7 +827,8 @@ ui::TextEditCommand GetTextEditCommandForMenuAction(SEL action) {
views::View::ConvertPointToTarget(target, hostedView_, &baselinePoint);
NSPoint baselinePointAppKit = NSMakePoint(
baselinePoint.x(), NSHeight([self frame]) - baselinePoint.y());
- [self showDefinitionForAttributedString:GetAttributedString(decoratedWord)
+ [self showDefinitionForAttributedString:
+ gfx::GetAttributedStringFromDecoratedText(decoratedWord)
atPoint:baselinePointAppKit];
}
« no previous file with comments | « ui/views/BUILD.gn ('k') | ui/views/controls/label.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698