OLD | NEW |
---|---|
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 #import "ui/base/cocoa/appkit_utils.h" | 13 #import "ui/base/cocoa/appkit_utils.h" |
14 #include "ui/base/cocoa/cocoa_base_utils.h" | 14 #include "ui/base/cocoa/cocoa_base_utils.h" |
15 #include "ui/base/dragdrop/drag_drop_types.h" | 15 #include "ui/base/dragdrop/drag_drop_types.h" |
16 #include "ui/base/dragdrop/os_exchange_data_provider_mac.h" | 16 #include "ui/base/dragdrop/os_exchange_data_provider_mac.h" |
17 #include "ui/base/ime/input_method.h" | 17 #include "ui/base/ime/input_method.h" |
18 #include "ui/base/ime/text_edit_commands.h" | 18 #include "ui/base/ime/text_edit_commands.h" |
19 #include "ui/base/ime/text_input_client.h" | 19 #include "ui/base/ime/text_input_client.h" |
20 #include "ui/compositor/canvas_painter.h" | 20 #include "ui/compositor/canvas_painter.h" |
21 #import "ui/events/cocoa/cocoa_event_utils.h" | 21 #import "ui/events/cocoa/cocoa_event_utils.h" |
22 #include "ui/events/event_utils.h" | 22 #include "ui/events/event_utils.h" |
23 #include "ui/events/keycodes/dom/dom_code.h" | 23 #include "ui/events/keycodes/dom/dom_code.h" |
24 #import "ui/events/keycodes/keyboard_code_conversion_mac.h" | 24 #import "ui/events/keycodes/keyboard_code_conversion_mac.h" |
25 #include "ui/gfx/canvas_paint_mac.h" | 25 #include "ui/gfx/canvas_paint_mac.h" |
26 #include "ui/gfx/decorated_text.h" | 26 #include "ui/gfx/decorated_text.h" |
27 #import "ui/gfx/decorated_text_mac.h" | |
27 #include "ui/gfx/geometry/rect.h" | 28 #include "ui/gfx/geometry/rect.h" |
28 #import "ui/gfx/mac/coordinate_conversion.h" | 29 #import "ui/gfx/mac/coordinate_conversion.h" |
29 #include "ui/gfx/path.h" | 30 #include "ui/gfx/path.h" |
30 #import "ui/gfx/path_mac.h" | 31 #import "ui/gfx/path_mac.h" |
31 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" | 32 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" |
32 #import "ui/views/cocoa/bridged_native_widget.h" | 33 #import "ui/views/cocoa/bridged_native_widget.h" |
33 #import "ui/views/cocoa/drag_drop_client_mac.h" | 34 #import "ui/views/cocoa/drag_drop_client_mac.h" |
34 #include "ui/views/controls/label.h" | 35 #include "ui/views/controls/label.h" |
35 #include "ui/views/controls/menu/menu_config.h" | 36 #include "ui/views/controls/menu/menu_config.h" |
36 #include "ui/views/controls/menu/menu_controller.h" | 37 #include "ui/views/controls/menu/menu_controller.h" |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
206 DCHECK([event type] == NSKeyDown || [event type] == NSKeyUp); | 207 DCHECK([event type] == NSKeyDown || [event type] == NSKeyUp); |
207 DCHECK_EQ(1u, [[event characters] length]); | 208 DCHECK_EQ(1u, [[event characters] length]); |
208 | 209 |
209 // [NSEvent characters] already considers the pressed key modifiers. Hence | 210 // [NSEvent characters] already considers the pressed key modifiers. Hence |
210 // send ui::EF_NONE as the key modifier to the KeyEvent constructor. | 211 // send ui::EF_NONE as the key modifier to the KeyEvent constructor. |
211 // E.g. For Alt+S, [NSEvent characters] is 'ß' and not 'S'. | 212 // E.g. For Alt+S, [NSEvent characters] is 'ß' and not 'S'. |
212 return ui::KeyEvent([[event characters] characterAtIndex:0], | 213 return ui::KeyEvent([[event characters] characterAtIndex:0], |
213 ui::KeyboardCodeFromNSEvent(event), ui::EF_NONE); | 214 ui::KeyboardCodeFromNSEvent(event), ui::EF_NONE); |
214 } | 215 } |
215 | 216 |
216 NSAttributedString* GetAttributedString( | |
217 const gfx::DecoratedText& decorated_text) { | |
218 base::scoped_nsobject<NSMutableAttributedString> str( | |
219 [[NSMutableAttributedString alloc] | |
220 initWithString:base::SysUTF16ToNSString(decorated_text.text)]); | |
221 [str beginEditing]; | |
222 | |
223 NSValue* const line_style = | |
224 @(NSUnderlineStyleSingle | NSUnderlinePatternSolid); | |
225 | |
226 for (const auto& attribute : decorated_text.attributes) { | |
227 DCHECK(!attribute.range.is_reversed()); | |
228 DCHECK_LE(attribute.range.end(), [str length]); | |
229 | |
230 NSMutableDictionary* attrs = [NSMutableDictionary dictionary]; | |
231 NSRange range = attribute.range.ToNSRange(); | |
232 | |
233 if (attribute.font.GetNativeFont()) | |
234 attrs[NSFontAttributeName] = attribute.font.GetNativeFont(); | |
235 | |
236 // NSFont does not have underline as an attribute. Hence handle it | |
237 // separately. | |
238 const bool underline = attribute.font.GetStyle() & gfx::Font::UNDERLINE; | |
239 if (underline) | |
240 attrs[NSUnderlineStyleAttributeName] = line_style; | |
241 | |
242 if (attribute.strike) | |
243 attrs[NSStrikethroughStyleAttributeName] = line_style; | |
244 | |
245 [str setAttributes:attrs range:range]; | |
246 } | |
247 | |
248 [str endEditing]; | |
249 return str.autorelease(); | |
250 } | |
251 | |
252 ui::TextEditCommand GetTextEditCommandForMenuAction(SEL action) { | 217 ui::TextEditCommand GetTextEditCommandForMenuAction(SEL action) { |
253 if (action == @selector(undo:)) | 218 if (action == @selector(undo:)) |
254 return ui::TextEditCommand::UNDO; | 219 return ui::TextEditCommand::UNDO; |
255 if (action == @selector(redo:)) | 220 if (action == @selector(redo:)) |
256 return ui::TextEditCommand::REDO; | 221 return ui::TextEditCommand::REDO; |
257 if (action == @selector(cut:)) | 222 if (action == @selector(cut:)) |
258 return ui::TextEditCommand::CUT; | 223 return ui::TextEditCommand::CUT; |
259 if (action == @selector(copy:)) | 224 if (action == @selector(copy:)) |
260 return ui::TextEditCommand::COPY; | 225 return ui::TextEditCommand::COPY; |
261 if (action == @selector(paste:)) | 226 if (action == @selector(paste:)) |
262 return ui::TextEditCommand::PASTE; | 227 return ui::TextEditCommand::PASTE; |
263 if (action == @selector(selectAll:)) | 228 if (action == @selector(selectAll:)) |
264 return ui::TextEditCommand::SELECT_ALL; | 229 return ui::TextEditCommand::SELECT_ALL; |
265 return ui::TextEditCommand::INVALID_COMMAND; | 230 return ui::TextEditCommand::INVALID_COMMAND; |
266 } | 231 } |
267 | 232 |
268 } // namespace | 233 } // namespace |
269 | 234 |
235 // TODO(spqchan): Implement support with the Speech submenu is in the main | |
tapted
2017/01/13 21:37:33
nit: with -> when
spqchan
2017/01/26 18:27:01
Done.
| |
236 // menu. | |
270 @interface BridgedContentView () | 237 @interface BridgedContentView () |
271 | 238 |
272 // Returns the active menu controller corresponding to |hostedView_|, | 239 // Returns the active menu controller corresponding to |hostedView_|, |
273 // nil otherwise. | 240 // nil otherwise. |
274 - (MenuController*)activeMenuController; | 241 - (MenuController*)activeMenuController; |
275 | 242 |
276 // Passes |event| to the InputMethod for dispatch. | 243 // Passes |event| to the InputMethod for dispatch. |
277 - (void)handleKeyEvent:(ui::KeyEvent*)event; | 244 - (void)handleKeyEvent:(ui::KeyEvent*)event; |
278 | 245 |
279 // Allows accelerators to be handled at different points in AppKit key event | 246 // Allows accelerators to be handled at different points in AppKit key event |
(...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
835 return; | 802 return; |
836 | 803 |
837 views::WordLookupClient* wordLookupClient = target->GetWordLookupClient(); | 804 views::WordLookupClient* wordLookupClient = target->GetWordLookupClient(); |
838 if (!wordLookupClient) | 805 if (!wordLookupClient) |
839 return; | 806 return; |
840 | 807 |
841 gfx::Point locationInTarget = locationInContent; | 808 gfx::Point locationInTarget = locationInContent; |
842 views::View::ConvertPointToTarget(hostedView_, target, &locationInTarget); | 809 views::View::ConvertPointToTarget(hostedView_, target, &locationInTarget); |
843 gfx::DecoratedText decoratedWord; | 810 gfx::DecoratedText decoratedWord; |
844 gfx::Point baselinePoint; | 811 gfx::Point baselinePoint; |
845 if (!wordLookupClient->GetDecoratedWordAtPoint( | 812 if (!wordLookupClient->GetDecoratedWordAndBaselineAtPoint( |
846 locationInTarget, &decoratedWord, &baselinePoint)) { | 813 locationInTarget, &decoratedWord, &baselinePoint)) { |
847 return; | 814 return; |
848 } | 815 } |
849 | 816 |
850 // Convert |baselinePoint| to the coordinate system of |hostedView_|. | 817 // Convert |baselinePoint| to the coordinate system of |hostedView_|. |
851 views::View::ConvertPointToTarget(target, hostedView_, &baselinePoint); | 818 views::View::ConvertPointToTarget(target, hostedView_, &baselinePoint); |
852 NSPoint baselinePointAppKit = NSMakePoint( | 819 NSPoint baselinePointAppKit = NSMakePoint( |
853 baselinePoint.x(), NSHeight([self frame]) - baselinePoint.y()); | 820 baselinePoint.x(), NSHeight([self frame]) - baselinePoint.y()); |
854 [self showDefinitionForAttributedString:GetAttributedString(decoratedWord) | 821 [self showDefinitionForAttributedString: |
822 gfx::GetAttributedStringFromDecoratedText(decoratedWord) | |
855 atPoint:baselinePointAppKit]; | 823 atPoint:baselinePointAppKit]; |
856 } | 824 } |
857 | 825 |
858 //////////////////////////////////////////////////////////////////////////////// | 826 //////////////////////////////////////////////////////////////////////////////// |
859 // NSResponder Action Messages. Keep sorted according NSResponder.h (from the | 827 // NSResponder Action Messages. Keep sorted according NSResponder.h (from the |
860 // 10.9 SDK). The list should eventually be complete. Anything not defined will | 828 // 10.9 SDK). The list should eventually be complete. Anything not defined will |
861 // beep when interpretKeyEvents: would otherwise call it. | 829 // beep when interpretKeyEvents: would otherwise call it. |
862 // TODO(tapted): Make this list complete, except for insert* methods which are | 830 // TODO(tapted): Make this list complete, except for insert* methods which are |
863 // dispatched as regular key events in doCommandBySelector:. | 831 // dispatched as regular key events in doCommandBySelector:. |
864 | 832 |
(...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1480 return [hostedView_->GetNativeViewAccessible() accessibilityHitTest:point]; | 1448 return [hostedView_->GetNativeViewAccessible() accessibilityHitTest:point]; |
1481 } | 1449 } |
1482 | 1450 |
1483 - (id)accessibilityFocusedUIElement { | 1451 - (id)accessibilityFocusedUIElement { |
1484 if (!hostedView_) | 1452 if (!hostedView_) |
1485 return nil; | 1453 return nil; |
1486 return [hostedView_->GetNativeViewAccessible() accessibilityFocusedUIElement]; | 1454 return [hostedView_->GetNativeViewAccessible() accessibilityFocusedUIElement]; |
1487 } | 1455 } |
1488 | 1456 |
1489 @end | 1457 @end |
OLD | NEW |