OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "content/browser/renderer_host/render_widget_host_view_mac.h" | 5 #include "content/browser/renderer_host/render_widget_host_view_mac.h" |
6 | 6 |
7 #include <QuartzCore/QuartzCore.h> | 7 #include <QuartzCore/QuartzCore.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 - (void)setRWHVDelegate:(NSObject<RenderWidgetHostViewMacDelegate>*)delegate; | 127 - (void)setRWHVDelegate:(NSObject<RenderWidgetHostViewMacDelegate>*)delegate; |
128 - (void)gotUnhandledWheelEvent; | 128 - (void)gotUnhandledWheelEvent; |
129 - (void)scrollOffsetPinnedToLeft:(BOOL)left toRight:(BOOL)right; | 129 - (void)scrollOffsetPinnedToLeft:(BOOL)left toRight:(BOOL)right; |
130 - (void)setHasHorizontalScrollbar:(BOOL)has_horizontal_scrollbar; | 130 - (void)setHasHorizontalScrollbar:(BOOL)has_horizontal_scrollbar; |
131 - (void)keyEvent:(NSEvent*)theEvent wasKeyEquivalent:(BOOL)equiv; | 131 - (void)keyEvent:(NSEvent*)theEvent wasKeyEquivalent:(BOOL)equiv; |
132 - (void)cancelChildPopups; | 132 - (void)cancelChildPopups; |
133 - (void)windowDidChangeBackingProperties:(NSNotification*)notification; | 133 - (void)windowDidChangeBackingProperties:(NSNotification*)notification; |
134 - (void)windowChangedScreen:(NSNotification*)notification; | 134 - (void)windowChangedScreen:(NSNotification*)notification; |
135 - (void)checkForPluginImeCancellation; | 135 - (void)checkForPluginImeCancellation; |
136 - (void)updateTabBackingStoreScaleFactor; | 136 - (void)updateTabBackingStoreScaleFactor; |
| 137 - (NSRect)firstViewRectForCharacterRange:(NSRange)theRange |
| 138 actualRange:(NSRangePointer)actualRange; |
137 @end | 139 @end |
138 | 140 |
139 // NSEvent subtype for scroll gestures events. | 141 // NSEvent subtype for scroll gestures events. |
140 static const short kIOHIDEventTypeScroll = 6; | 142 static const short kIOHIDEventTypeScroll = 6; |
141 | 143 |
142 // A window subclass that allows the fullscreen window to become main and gain | 144 // A window subclass that allows the fullscreen window to become main and gain |
143 // keyboard focus. This is only used for pepper flash. Normal fullscreen is | 145 // keyboard focus. This is only used for pepper flash. Normal fullscreen is |
144 // handled by the browser. | 146 // handled by the browser. |
145 @interface PepperFlashFullscreenWindow : UnderlayOpenGLHostingWindow | 147 @interface PepperFlashFullscreenWindow : UnderlayOpenGLHostingWindow |
146 @end | 148 @end |
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
758 } | 760 } |
759 | 761 |
760 // | 762 // |
761 // RenderWidgetHostViewCocoa uses the stored selection text, | 763 // RenderWidgetHostViewCocoa uses the stored selection text, |
762 // which implements NSServicesRequests protocol. | 764 // which implements NSServicesRequests protocol. |
763 // | 765 // |
764 void RenderWidgetHostViewMac::SelectionChanged(const string16& text, | 766 void RenderWidgetHostViewMac::SelectionChanged(const string16& text, |
765 size_t offset, | 767 size_t offset, |
766 const ui::Range& range) { | 768 const ui::Range& range) { |
767 if (range.is_empty() || text.empty()) { | 769 if (range.is_empty() || text.empty()) { |
768 selected_text_.clear(); | 770 selected_text_.clear(); |
769 } else { | 771 } else { |
770 size_t pos = range.GetMin() - offset; | 772 size_t pos = range.GetMin() - offset; |
771 size_t n = range.length(); | 773 size_t n = range.length(); |
772 | 774 |
773 DCHECK(pos + n <= text.length()) << "The text can not fully cover range."; | 775 DCHECK(pos + n <= text.length()) << "The text can not fully cover range."; |
774 if (pos >= text.length()) { | 776 if (pos >= text.length()) { |
775 DCHECK(false) << "The text can not cover range."; | 777 DCHECK(false) << "The text can not cover range."; |
776 return; | 778 return; |
777 } | 779 } |
778 selected_text_ = UTF16ToUTF8(text.substr(pos, n)); | 780 selected_text_ = UTF16ToUTF8(text.substr(pos, n)); |
779 } | 781 } |
780 | 782 |
781 [cocoa_view_ setSelectedRange:range.ToNSRange()]; | 783 [cocoa_view_ setSelectedRange:range.ToNSRange()]; |
782 // Updaes markedRange when there is no marked text so that retrieving | 784 // Updates markedRange when there is no marked text so that retrieving |
783 // markedRange immediately after calling setMarkdText: returns the current | 785 // markedRange immediately after calling setMarkdText: returns the current |
784 // caret position. | 786 // caret position. |
785 if (![cocoa_view_ hasMarkedText]) { | 787 if (![cocoa_view_ hasMarkedText]) { |
786 [cocoa_view_ setMarkedRange:range.ToNSRange()]; | 788 [cocoa_view_ setMarkedRange:range.ToNSRange()]; |
787 } | 789 } |
788 | 790 |
789 RenderWidgetHostViewBase::SelectionChanged(text, offset, range); | 791 RenderWidgetHostViewBase::SelectionChanged(text, offset, range); |
790 } | 792 } |
791 | 793 |
792 void RenderWidgetHostViewMac::SetShowingContextMenu(bool showing) { | 794 void RenderWidgetHostViewMac::SetShowingContextMenu(bool showing) { |
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1392 } | 1394 } |
1393 | 1395 |
1394 void RenderWidgetHostViewMac::WindowFrameChanged() { | 1396 void RenderWidgetHostViewMac::WindowFrameChanged() { |
1395 if (render_widget_host_) { | 1397 if (render_widget_host_) { |
1396 render_widget_host_->Send(new ViewMsg_WindowFrameChanged( | 1398 render_widget_host_->Send(new ViewMsg_WindowFrameChanged( |
1397 render_widget_host_->GetRoutingID(), GetBoundsInRootWindow(), | 1399 render_widget_host_->GetRoutingID(), GetBoundsInRootWindow(), |
1398 GetViewBounds())); | 1400 GetViewBounds())); |
1399 } | 1401 } |
1400 } | 1402 } |
1401 | 1403 |
| 1404 void RenderWidgetHostViewMac::ShowDefinitionForSelection() { |
| 1405 // Brings up either Dictionary.app or a light-weight dictionary panel, |
| 1406 // depending on system settings. |
| 1407 NSRange selection_range = [cocoa_view_ selectedRange]; |
| 1408 NSAttributedString* attr_string = |
| 1409 [cocoa_view_ attributedSubstringForProposedRange:selection_range |
| 1410 actualRange:nil]; |
| 1411 NSRect rect = [cocoa_view_ firstViewRectForCharacterRange:selection_range |
| 1412 actualRange:nil]; |
| 1413 |
| 1414 // Set |rect.origin| to the text baseline based on |attr_string|'s font, |
| 1415 // since -baselineDeltaForCharacterAtIndex: is currently not implemented. |
| 1416 NSDictionary* attrs = [attr_string attributesAtIndex:0 effectiveRange:nil]; |
| 1417 NSFont* font = [attrs objectForKey:NSFontAttributeName]; |
| 1418 rect.origin.y += NSHeight(rect) - [font ascender]; |
| 1419 [cocoa_view_ showDefinitionForAttributedString:attr_string |
| 1420 atPoint:rect.origin]; |
| 1421 } |
| 1422 |
1402 void RenderWidgetHostViewMac::SetBackground(const SkBitmap& background) { | 1423 void RenderWidgetHostViewMac::SetBackground(const SkBitmap& background) { |
1403 RenderWidgetHostViewBase::SetBackground(background); | 1424 RenderWidgetHostViewBase::SetBackground(background); |
1404 if (render_widget_host_) | 1425 if (render_widget_host_) |
1405 render_widget_host_->Send(new ViewMsg_SetBackground( | 1426 render_widget_host_->Send(new ViewMsg_SetBackground( |
1406 render_widget_host_->GetRoutingID(), background)); | 1427 render_widget_host_->GetRoutingID(), background)); |
1407 } | 1428 } |
1408 | 1429 |
1409 void RenderWidgetHostViewMac::OnAccessibilityNotifications( | 1430 void RenderWidgetHostViewMac::OnAccessibilityNotifications( |
1410 const std::vector<AccessibilityHostMsg_NotificationParams>& params) { | 1431 const std::vector<AccessibilityHostMsg_NotificationParams>& params) { |
1411 if (!GetBrowserAccessibilityManager()) { | 1432 if (!GetBrowserAccessibilityManager()) { |
(...skipping 1378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2790 thePoint = [self convertPoint:thePoint fromView:nil]; | 2811 thePoint = [self convertPoint:thePoint fromView:nil]; |
2791 thePoint.y = NSHeight([self frame]) - thePoint.y; | 2812 thePoint.y = NSHeight([self frame]) - thePoint.y; |
2792 | 2813 |
2793 NSUInteger index = | 2814 NSUInteger index = |
2794 TextInputClientMac::GetInstance()->GetCharacterIndexAtPoint( | 2815 TextInputClientMac::GetInstance()->GetCharacterIndexAtPoint( |
2795 renderWidgetHostView_->render_widget_host_, | 2816 renderWidgetHostView_->render_widget_host_, |
2796 gfx::Point(thePoint.x, thePoint.y)); | 2817 gfx::Point(thePoint.x, thePoint.y)); |
2797 return index; | 2818 return index; |
2798 } | 2819 } |
2799 | 2820 |
2800 - (NSRect)firstRectForCharacterRange:(NSRange)theRange | 2821 - (NSRect)firstViewRectForCharacterRange:(NSRange)theRange |
2801 actualRange:(NSRangePointer)actualRange { | 2822 actualRange:(NSRangePointer)actualRange { |
2802 NSRect rect; | 2823 NSRect rect; |
2803 if (!renderWidgetHostView_->GetCachedFirstRectForCharacterRange( | 2824 if (!renderWidgetHostView_->GetCachedFirstRectForCharacterRange( |
2804 theRange, | 2825 theRange, |
2805 &rect, | 2826 &rect, |
2806 actualRange)) { | 2827 actualRange)) { |
2807 rect = TextInputClientMac::GetInstance()->GetFirstRectForRange( | 2828 rect = TextInputClientMac::GetInstance()->GetFirstRectForRange( |
2808 renderWidgetHostView_->render_widget_host_, theRange); | 2829 renderWidgetHostView_->render_widget_host_, theRange); |
2809 | 2830 |
2810 // TODO(thakis): Pipe |actualRange| through TextInputClientMac machinery. | 2831 // TODO(thakis): Pipe |actualRange| through TextInputClientMac machinery. |
2811 if (actualRange) | 2832 if (actualRange) |
2812 *actualRange = theRange; | 2833 *actualRange = theRange; |
2813 } | 2834 } |
2814 | 2835 |
2815 // The returned rectangle is in WebKit coordinates (upper left origin), so | 2836 // The returned rectangle is in WebKit coordinates (upper left origin), so |
2816 // flip the coordinate system and then convert it into screen coordinates for | 2837 // flip the coordinate system. |
2817 // return. | |
2818 NSRect viewFrame = [self frame]; | 2838 NSRect viewFrame = [self frame]; |
2819 rect.origin.y = NSHeight(viewFrame) - NSMaxY(rect); | 2839 rect.origin.y = NSHeight(viewFrame) - NSMaxY(rect); |
| 2840 return rect; |
| 2841 } |
| 2842 |
| 2843 - (NSRect)firstRectForCharacterRange:(NSRange)theRange |
| 2844 actualRange:(NSRangePointer)actualRange { |
| 2845 NSRect rect = [self firstViewRectForCharacterRange:theRange |
| 2846 actualRange:actualRange]; |
| 2847 |
| 2848 // Convert into screen coordinates for return. |
2820 rect = [self convertRect:rect toView:nil]; | 2849 rect = [self convertRect:rect toView:nil]; |
2821 rect.origin = [[self window] convertBaseToScreen:rect.origin]; | 2850 rect.origin = [[self window] convertBaseToScreen:rect.origin]; |
2822 return rect; | 2851 return rect; |
2823 } | 2852 } |
2824 | 2853 |
2825 - (NSRange)markedRange { | 2854 - (NSRange)markedRange { |
2826 // An input method calls this method to check if an application really has | 2855 // An input method calls this method to check if an application really has |
2827 // a text being composed when hasMarkedText call returns true. | 2856 // a text being composed when hasMarkedText call returns true. |
2828 // Returns the range saved in the setMarkedText method so the input method | 2857 // Returns the range saved in the setMarkedText method so the input method |
2829 // calls the setMarkedText method and we can update the composition node | 2858 // calls the setMarkedText method and we can update the composition node |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3221 if (!string) return NO; | 3250 if (!string) return NO; |
3222 | 3251 |
3223 // If the user is currently using an IME, confirm the IME input, | 3252 // If the user is currently using an IME, confirm the IME input, |
3224 // and then insert the text from the service, the same as TextEdit and Safari. | 3253 // and then insert the text from the service, the same as TextEdit and Safari. |
3225 [self confirmComposition]; | 3254 [self confirmComposition]; |
3226 [self insertText:string]; | 3255 [self insertText:string]; |
3227 return YES; | 3256 return YES; |
3228 } | 3257 } |
3229 | 3258 |
3230 @end | 3259 @end |
OLD | NEW |