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

Side by Side Diff: ui/gfx/decorated_text_mac.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 unified diff | Download patch
« no previous file with comments | « ui/gfx/decorated_text_mac.h ('k') | ui/gfx/render_text.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #import "ui/gfx/decorated_text_mac.h"
6
7 #import <Cocoa/Cocoa.h>
8
9 #import "base/mac/scoped_nsobject.h"
10 #include "base/strings/sys_string_conversions.h"
11 #include "ui/gfx/decorated_text.h"
12
13 namespace gfx {
14
15 NSAttributedString* GetAttributedStringFromDecoratedText(
16 const DecoratedText& decorated_text) {
17 base::scoped_nsobject<NSMutableAttributedString> str(
18 [[NSMutableAttributedString alloc]
19 initWithString:base::SysUTF16ToNSString(decorated_text.text)]);
20 [str beginEditing];
21
22 NSValue* const line_style =
23 @(NSUnderlineStyleSingle | NSUnderlinePatternSolid);
24
25 for (const auto& attribute : decorated_text.attributes) {
26 DCHECK(!attribute.range.is_reversed());
27 DCHECK_LE(attribute.range.end(), [str length]);
28
29 NSMutableDictionary* attrs = [NSMutableDictionary dictionary];
30 NSRange range = attribute.range.ToNSRange();
31
32 if (attribute.font.GetNativeFont())
33 attrs[NSFontAttributeName] = attribute.font.GetNativeFont();
34
35 // NSFont does not have underline as an attribute. Hence handle it
36 // separately.
37 const bool underline = attribute.font.GetStyle() & gfx::Font::UNDERLINE;
38 if (underline)
39 attrs[NSUnderlineStyleAttributeName] = line_style;
40
41 if (attribute.strike)
42 attrs[NSStrikethroughStyleAttributeName] = line_style;
43
44 [str setAttributes:attrs range:range];
45 }
46
47 [str endEditing];
48 return str.autorelease();
49 }
50
51 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/decorated_text_mac.h ('k') | ui/gfx/render_text.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698