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

Side by Side 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: Addressed tapted's comments and made things work Created 4 years 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "ui/views/cocoa/bridged_content_view.h" 5 #import "ui/views/cocoa/bridged_content_view.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #import "base/mac/mac_util.h" 8 #import "base/mac/mac_util.h"
9 #import "base/mac/scoped_nsobject.h" 9 #import "base/mac/scoped_nsobject.h"
10 #import "base/mac/sdk_forward_declarations.h" 10 #import "base/mac/sdk_forward_declarations.h"
11 #include "base/strings/sys_string_conversions.h" 11 #include "base/strings/sys_string_conversions.h"
12 #include "skia/ext/skia_utils_mac.h" 12 #include "skia/ext/skia_utils_mac.h"
13 #include "ui/base/cocoa/cocoa_base_utils.h" 13 #include "ui/base/cocoa/cocoa_base_utils.h"
14 #include "ui/base/dragdrop/drag_drop_types.h" 14 #include "ui/base/dragdrop/drag_drop_types.h"
15 #include "ui/base/dragdrop/os_exchange_data_provider_mac.h" 15 #include "ui/base/dragdrop/os_exchange_data_provider_mac.h"
16 #include "ui/base/ime/input_method.h" 16 #include "ui/base/ime/input_method.h"
17 #include "ui/base/ime/text_edit_commands.h" 17 #include "ui/base/ime/text_edit_commands.h"
18 #include "ui/base/ime/text_input_client.h" 18 #include "ui/base/ime/text_input_client.h"
19 #include "ui/compositor/canvas_painter.h" 19 #include "ui/compositor/canvas_painter.h"
20 #import "ui/events/cocoa/cocoa_event_utils.h" 20 #import "ui/events/cocoa/cocoa_event_utils.h"
21 #include "ui/events/event_utils.h" 21 #include "ui/events/event_utils.h"
22 #include "ui/events/keycodes/dom/dom_code.h" 22 #include "ui/events/keycodes/dom/dom_code.h"
23 #import "ui/events/keycodes/keyboard_code_conversion_mac.h" 23 #import "ui/events/keycodes/keyboard_code_conversion_mac.h"
24 #include "ui/gfx/canvas_paint_mac.h" 24 #include "ui/gfx/canvas_paint_mac.h"
25 #include "ui/gfx/decorated_text.h" 25 #include "ui/gfx/decorated_text.h"
26 #include "ui/gfx/decorated_text_mac.h"
26 #include "ui/gfx/geometry/rect.h" 27 #include "ui/gfx/geometry/rect.h"
27 #import "ui/gfx/mac/coordinate_conversion.h" 28 #import "ui/gfx/mac/coordinate_conversion.h"
28 #include "ui/gfx/path.h" 29 #include "ui/gfx/path.h"
29 #import "ui/gfx/path_mac.h" 30 #import "ui/gfx/path_mac.h"
30 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" 31 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h"
31 #import "ui/views/cocoa/bridged_native_widget.h" 32 #import "ui/views/cocoa/bridged_native_widget.h"
32 #import "ui/views/cocoa/drag_drop_client_mac.h" 33 #import "ui/views/cocoa/drag_drop_client_mac.h"
33 #include "ui/views/controls/label.h" 34 #include "ui/views/controls/label.h"
34 #include "ui/views/controls/menu/menu_config.h" 35 #include "ui/views/controls/menu/menu_config.h"
35 #include "ui/views/controls/menu/menu_controller.h" 36 #include "ui/views/controls/menu/menu_controller.h"
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 DCHECK([event type] == NSKeyDown || [event type] == NSKeyUp); 206 DCHECK([event type] == NSKeyDown || [event type] == NSKeyUp);
206 DCHECK_EQ(1u, [[event characters] length]); 207 DCHECK_EQ(1u, [[event characters] length]);
207 208
208 // [NSEvent characters] already considers the pressed key modifiers. Hence 209 // [NSEvent characters] already considers the pressed key modifiers. Hence
209 // send ui::EF_NONE as the key modifier to the KeyEvent constructor. 210 // send ui::EF_NONE as the key modifier to the KeyEvent constructor.
210 // E.g. For Alt+S, [NSEvent characters] is 'ß' and not 'S'. 211 // E.g. For Alt+S, [NSEvent characters] is 'ß' and not 'S'.
211 return ui::KeyEvent([[event characters] characterAtIndex:0], 212 return ui::KeyEvent([[event characters] characterAtIndex:0],
212 ui::KeyboardCodeFromNSEvent(event), ui::EF_NONE); 213 ui::KeyboardCodeFromNSEvent(event), ui::EF_NONE);
213 } 214 }
214 215
215 NSAttributedString* GetAttributedString(
216 const gfx::DecoratedText& decorated_text) {
217 base::scoped_nsobject<NSMutableAttributedString> str(
218 [[NSMutableAttributedString alloc]
219 initWithString:base::SysUTF16ToNSString(decorated_text.text)]);
220 [str beginEditing];
221
222 NSValue* const line_style =
223 @(NSUnderlineStyleSingle | NSUnderlinePatternSolid);
224
225 for (const auto& attribute : decorated_text.attributes) {
226 DCHECK(!attribute.range.is_reversed());
227 DCHECK_LE(attribute.range.end(), [str length]);
228
229 NSMutableDictionary* attrs = [NSMutableDictionary dictionary];
230 NSRange range = attribute.range.ToNSRange();
231
232 if (attribute.font.GetNativeFont())
233 attrs[NSFontAttributeName] = attribute.font.GetNativeFont();
234
235 // NSFont does not have underline as an attribute. Hence handle it
236 // separately.
237 const bool underline = attribute.font.GetStyle() & gfx::Font::UNDERLINE;
238 if (underline)
239 attrs[NSUnderlineStyleAttributeName] = line_style;
240
241 if (attribute.strike)
242 attrs[NSStrikethroughStyleAttributeName] = line_style;
243
244 [str setAttributes:attrs range:range];
245 }
246
247 [str endEditing];
248 return str.autorelease();
249 }
250
251 ui::TextEditCommand GetTextEditCommandForMenuAction(SEL action) { 216 ui::TextEditCommand GetTextEditCommandForMenuAction(SEL action) {
252 if (action == @selector(undo:)) 217 if (action == @selector(undo:))
253 return ui::TextEditCommand::UNDO; 218 return ui::TextEditCommand::UNDO;
254 if (action == @selector(redo:)) 219 if (action == @selector(redo:))
255 return ui::TextEditCommand::REDO; 220 return ui::TextEditCommand::REDO;
256 if (action == @selector(cut:)) 221 if (action == @selector(cut:))
257 return ui::TextEditCommand::CUT; 222 return ui::TextEditCommand::CUT;
258 if (action == @selector(copy:)) 223 if (action == @selector(copy:))
259 return ui::TextEditCommand::COPY; 224 return ui::TextEditCommand::COPY;
260 if (action == @selector(paste:)) 225 if (action == @selector(paste:))
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after
838 gfx::Point baselinePoint; 803 gfx::Point baselinePoint;
839 if (!wordLookupClient->GetDecoratedWordAtPoint( 804 if (!wordLookupClient->GetDecoratedWordAtPoint(
840 locationInTarget, &decoratedWord, &baselinePoint)) { 805 locationInTarget, &decoratedWord, &baselinePoint)) {
841 return; 806 return;
842 } 807 }
843 808
844 // Convert |baselinePoint| to the coordinate system of |hostedView_|. 809 // Convert |baselinePoint| to the coordinate system of |hostedView_|.
845 views::View::ConvertPointToTarget(target, hostedView_, &baselinePoint); 810 views::View::ConvertPointToTarget(target, hostedView_, &baselinePoint);
846 NSPoint baselinePointAppKit = NSMakePoint( 811 NSPoint baselinePointAppKit = NSMakePoint(
847 baselinePoint.x(), NSHeight([self frame]) - baselinePoint.y()); 812 baselinePoint.x(), NSHeight([self frame]) - baselinePoint.y());
848 [self showDefinitionForAttributedString:GetAttributedString(decoratedWord) 813 [self showDefinitionForAttributedString:
814 gfx::GetAttributedStringFromDecoratedText(decoratedWord)
849 atPoint:baselinePointAppKit]; 815 atPoint:baselinePointAppKit];
850 } 816 }
851 817
852 //////////////////////////////////////////////////////////////////////////////// 818 ////////////////////////////////////////////////////////////////////////////////
853 // NSResponder Action Messages. Keep sorted according NSResponder.h (from the 819 // NSResponder Action Messages. Keep sorted according NSResponder.h (from the
854 // 10.9 SDK). The list should eventually be complete. Anything not defined will 820 // 10.9 SDK). The list should eventually be complete. Anything not defined will
855 // beep when interpretKeyEvents: would otherwise call it. 821 // beep when interpretKeyEvents: would otherwise call it.
856 // TODO(tapted): Make this list complete, except for insert* methods which are 822 // TODO(tapted): Make this list complete, except for insert* methods which are
857 // dispatched as regular key events in doCommandBySelector:. 823 // dispatched as regular key events in doCommandBySelector:.
858 824
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after
1470 return [hostedView_->GetNativeViewAccessible() accessibilityHitTest:point]; 1436 return [hostedView_->GetNativeViewAccessible() accessibilityHitTest:point];
1471 } 1437 }
1472 1438
1473 - (id)accessibilityFocusedUIElement { 1439 - (id)accessibilityFocusedUIElement {
1474 if (!hostedView_) 1440 if (!hostedView_)
1475 return nil; 1441 return nil;
1476 return [hostedView_->GetNativeViewAccessible() accessibilityFocusedUIElement]; 1442 return [hostedView_->GetNativeViewAccessible() accessibilityFocusedUIElement];
1477 } 1443 }
1478 1444
1479 @end 1445 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698