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

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

Issue 2688883002: Revert [MacViews] Implemented text context menu (Closed)
Patch Set: 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 b47f522dd7c759f2f1450c06c5eb9b544bfe0806..1796fff92a576f87b724a6acb8d6182c27da72b9 100644
--- a/ui/views/cocoa/bridged_content_view.mm
+++ b/ui/views/cocoa/bridged_content_view.mm
@@ -24,7 +24,6 @@
#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"
@@ -201,6 +200,42 @@ 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;
@@ -219,8 +254,6 @@ 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_|,
@@ -818,7 +851,7 @@ ui::TextEditCommand GetTextEditCommandForMenuAction(SEL action) {
views::View::ConvertPointToTarget(hostedView_, target, &locationInTarget);
gfx::DecoratedText decoratedWord;
gfx::Point baselinePoint;
- if (!wordLookupClient->GetDecoratedWordAndBaselineAtPoint(
+ if (!wordLookupClient->GetDecoratedWordAtPoint(
locationInTarget, &decoratedWord, &baselinePoint)) {
return;
}
@@ -827,8 +860,7 @@ ui::TextEditCommand GetTextEditCommandForMenuAction(SEL action) {
views::View::ConvertPointToTarget(target, hostedView_, &baselinePoint);
NSPoint baselinePointAppKit = NSMakePoint(
baselinePoint.x(), NSHeight([self frame]) - baselinePoint.y());
- [self showDefinitionForAttributedString:
- gfx::GetAttributedStringFromDecoratedText(decoratedWord)
+ [self showDefinitionForAttributedString:GetAttributedString(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