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 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
11 #include "skia/ext/skia_utils_mac.h" | 11 #include "skia/ext/skia_utils_mac.h" |
12 #include "ui/base/cocoa/cocoa_base_utils.h" | 12 #include "ui/base/cocoa/cocoa_base_utils.h" |
13 #include "ui/base/dragdrop/drag_drop_types.h" | 13 #include "ui/base/dragdrop/drag_drop_types.h" |
14 #include "ui/base/dragdrop/os_exchange_data_provider_mac.h" | 14 #include "ui/base/dragdrop/os_exchange_data_provider_mac.h" |
15 #include "ui/base/ime/input_method.h" | 15 #include "ui/base/ime/input_method.h" |
16 #include "ui/base/ime/text_edit_commands.h" | 16 #include "ui/base/ime/text_edit_commands.h" |
17 #include "ui/base/ime/text_input_client.h" | 17 #include "ui/base/ime/text_input_client.h" |
18 #include "ui/compositor/canvas_painter.h" | 18 #include "ui/compositor/canvas_painter.h" |
19 #import "ui/events/cocoa/cocoa_event_utils.h" | 19 #import "ui/events/cocoa/cocoa_event_utils.h" |
20 #include "ui/events/event_utils.h" | |
20 #include "ui/events/keycodes/dom/dom_code.h" | 21 #include "ui/events/keycodes/dom/dom_code.h" |
21 #import "ui/events/keycodes/keyboard_code_conversion_mac.h" | 22 #import "ui/events/keycodes/keyboard_code_conversion_mac.h" |
22 #include "ui/gfx/canvas_paint_mac.h" | 23 #include "ui/gfx/canvas_paint_mac.h" |
24 #include "ui/gfx/decorated_text.h" | |
23 #include "ui/gfx/geometry/rect.h" | 25 #include "ui/gfx/geometry/rect.h" |
24 #import "ui/gfx/mac/coordinate_conversion.h" | 26 #import "ui/gfx/mac/coordinate_conversion.h" |
25 #include "ui/gfx/path.h" | 27 #include "ui/gfx/path.h" |
26 #import "ui/gfx/path_mac.h" | 28 #import "ui/gfx/path_mac.h" |
29 #include "ui/gfx/render_text.h" | |
27 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" | 30 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" |
28 #import "ui/views/cocoa/bridged_native_widget.h" | 31 #import "ui/views/cocoa/bridged_native_widget.h" |
29 #import "ui/views/cocoa/drag_drop_client_mac.h" | 32 #import "ui/views/cocoa/drag_drop_client_mac.h" |
30 #include "ui/views/controls/menu/menu_config.h" | 33 #include "ui/views/controls/menu/menu_config.h" |
31 #include "ui/views/controls/menu/menu_controller.h" | 34 #include "ui/views/controls/menu/menu_controller.h" |
32 #include "ui/views/view.h" | 35 #include "ui/views/view.h" |
33 #include "ui/views/widget/native_widget_mac.h" | 36 #include "ui/views/widget/native_widget_mac.h" |
34 #include "ui/views/widget/widget.h" | 37 #include "ui/views/widget/widget.h" |
35 | 38 |
36 using views::MenuController; | 39 using views::MenuController; |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
200 DCHECK([event type] == NSKeyDown || [event type] == NSKeyUp); | 203 DCHECK([event type] == NSKeyDown || [event type] == NSKeyUp); |
201 DCHECK_EQ(1u, [[event characters] length]); | 204 DCHECK_EQ(1u, [[event characters] length]); |
202 | 205 |
203 // [NSEvent characters] already considers the pressed key modifiers. Hence | 206 // [NSEvent characters] already considers the pressed key modifiers. Hence |
204 // send ui::EF_NONE as the key modifier to the KeyEvent constructor. | 207 // send ui::EF_NONE as the key modifier to the KeyEvent constructor. |
205 // E.g. For Alt+S, [NSEvent characters] is 'ß' and not 'S'. | 208 // E.g. For Alt+S, [NSEvent characters] is 'ß' and not 'S'. |
206 return ui::KeyEvent([[event characters] characterAtIndex:0], | 209 return ui::KeyEvent([[event characters] characterAtIndex:0], |
207 ui::KeyboardCodeFromNSEvent(event), ui::EF_NONE); | 210 ui::KeyboardCodeFromNSEvent(event), ui::EF_NONE); |
208 } | 211 } |
209 | 212 |
213 NSAttributedString* GetAttributedString( | |
214 const gfx::DecoratedText& decorated_text) { | |
215 base::scoped_nsobject<NSMutableAttributedString> str( | |
216 [[NSMutableAttributedString alloc] init]); | |
217 [str beginEditing]; | |
218 [[str mutableString] setString:base::SysUTF16ToNSString(decorated_text.text)]; | |
219 | |
220 for (const auto& attribute : decorated_text.attributes) { | |
221 DCHECK(!attribute.range.is_reversed()); | |
222 DCHECK_LE(attribute.range.end(), [str length]); | |
223 | |
224 NSMutableDictionary* attrs = [NSMutableDictionary dictionary]; | |
225 NSRange range = attribute.range.ToNSRange(); | |
226 | |
227 if (attribute.font.GetNativeFont()) { | |
228 [attrs setObject:attribute.font.GetNativeFont() | |
229 forKey:NSFontAttributeName]; | |
230 } | |
231 | |
232 // NSFont does not have underline as an attribute. Hence handle it | |
233 // separately. | |
234 const bool underline = attribute.font.GetStyle() & gfx::Font::UNDERLINE; | |
235 if (underline) { | |
236 [attrs setObject:@(NSUnderlineStyleSingle | NSUnderlinePatternSolid) | |
237 forKey:NSUnderlineStyleAttributeName]; | |
238 } | |
239 | |
240 if (attribute.strike) { | |
241 [attrs setObject:@(NSUnderlineStyleSingle | NSUnderlinePatternSolid) | |
242 forKey:NSStrikethroughStyleAttributeName]; | |
243 } | |
244 | |
245 [str setAttributes:attrs range:range]; | |
246 } | |
247 | |
248 [str endEditing]; | |
249 return [str.release() autorelease]; | |
tapted
2016/09/26 08:07:26
return str.autorelease();
karandeepb
2016/09/26 09:22:07
Done.
| |
250 } | |
251 | |
210 } // namespace | 252 } // namespace |
211 | 253 |
212 @interface BridgedContentView () | 254 @interface BridgedContentView () |
213 | 255 |
214 // Returns the active menu controller corresponding to |hostedView_|, | 256 // Returns the active menu controller corresponding to |hostedView_|, |
215 // nil otherwise. | 257 // nil otherwise. |
216 - (MenuController*)activeMenuController; | 258 - (MenuController*)activeMenuController; |
217 | 259 |
218 // Passes |event| to the InputMethod for dispatch. | 260 // Passes |event| to the InputMethod for dispatch. |
219 - (void)handleKeyEvent:(ui::KeyEvent*)event; | 261 - (void)handleKeyEvent:(ui::KeyEvent*)event; |
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
733 } | 775 } |
734 | 776 |
735 - (void)scrollWheel:(NSEvent*)theEvent { | 777 - (void)scrollWheel:(NSEvent*)theEvent { |
736 if (!hostedView_) | 778 if (!hostedView_) |
737 return; | 779 return; |
738 | 780 |
739 ui::MouseWheelEvent event(theEvent); | 781 ui::MouseWheelEvent event(theEvent); |
740 hostedView_->GetWidget()->OnMouseEvent(&event); | 782 hostedView_->GetWidget()->OnMouseEvent(&event); |
741 } | 783 } |
742 | 784 |
785 - (void)quickLookWithEvent:(NSEvent*)theEvent { | |
786 if (!hostedView_) | |
787 return; | |
788 | |
789 const gfx::Point locationInContent = ui::EventLocationFromNative(theEvent); | |
790 views::View* target = hostedView_->GetEventHandlerForPoint(locationInContent); | |
791 if (!target) | |
792 return; | |
793 | |
794 gfx::RenderText* renderText = target->GetRenderText(); | |
795 if (!renderText) | |
796 return; | |
797 | |
798 gfx::Point locationInTarget = locationInContent; | |
799 views::View::ConvertPointToTarget(hostedView_, target, &locationInTarget); | |
800 gfx::DecoratedText decorated_word; | |
801 gfx::Point baselinePoint; | |
802 if (!renderText->GetDecoratedWordAtPoint(locationInTarget, &decorated_word, | |
803 &baselinePoint)) { | |
804 return; | |
805 } | |
806 | |
807 // Convert |baselinePoint| to the coordinate system of |hostedView_|. | |
808 views::View::ConvertPointToTarget(target, hostedView_, &baselinePoint); | |
809 NSPoint baselinePointAppKit = NSMakePoint( | |
810 baselinePoint.x(), NSHeight([self frame]) - baselinePoint.y()); | |
811 [self showDefinitionForAttributedString:GetAttributedString(decorated_word) | |
812 atPoint:baselinePointAppKit]; | |
813 } | |
814 | |
743 //////////////////////////////////////////////////////////////////////////////// | 815 //////////////////////////////////////////////////////////////////////////////// |
744 // NSResponder Action Messages. Keep sorted according NSResponder.h (from the | 816 // NSResponder Action Messages. Keep sorted according NSResponder.h (from the |
745 // 10.9 SDK). The list should eventually be complete. Anything not defined will | 817 // 10.9 SDK). The list should eventually be complete. Anything not defined will |
746 // beep when interpretKeyEvents: would otherwise call it. | 818 // beep when interpretKeyEvents: would otherwise call it. |
747 // TODO(tapted): Make this list complete, except for insert* methods which are | 819 // TODO(tapted): Make this list complete, except for insert* methods which are |
748 // dispatched as regular key events in doCommandBySelector:. | 820 // dispatched as regular key events in doCommandBySelector:. |
749 | 821 |
750 // views::Textfields are single-line only, map Paragraph and Document commands | 822 // views::Textfields are single-line only, map Paragraph and Document commands |
751 // to Line. Also, Up/Down commands correspond to beginning/end of line. | 823 // to Line. Also, Up/Down commands correspond to beginning/end of line. |
752 | 824 |
(...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1356 } | 1428 } |
1357 | 1429 |
1358 return [super accessibilityAttributeValue:attribute]; | 1430 return [super accessibilityAttributeValue:attribute]; |
1359 } | 1431 } |
1360 | 1432 |
1361 - (id)accessibilityHitTest:(NSPoint)point { | 1433 - (id)accessibilityHitTest:(NSPoint)point { |
1362 return [hostedView_->GetNativeViewAccessible() accessibilityHitTest:point]; | 1434 return [hostedView_->GetNativeViewAccessible() accessibilityHitTest:point]; |
1363 } | 1435 } |
1364 | 1436 |
1365 @end | 1437 @end |
OLD | NEW |