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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
133 - (void)setRWHVDelegate:(NSObject<RenderWidgetHostViewMacDelegate>*)delegate; | 133 - (void)setRWHVDelegate:(NSObject<RenderWidgetHostViewMacDelegate>*)delegate; |
134 - (void)gotUnhandledWheelEvent; | 134 - (void)gotUnhandledWheelEvent; |
135 - (void)scrollOffsetPinnedToLeft:(BOOL)left toRight:(BOOL)right; | 135 - (void)scrollOffsetPinnedToLeft:(BOOL)left toRight:(BOOL)right; |
136 - (void)setHasHorizontalScrollbar:(BOOL)has_horizontal_scrollbar; | 136 - (void)setHasHorizontalScrollbar:(BOOL)has_horizontal_scrollbar; |
137 - (void)keyEvent:(NSEvent*)theEvent wasKeyEquivalent:(BOOL)equiv; | 137 - (void)keyEvent:(NSEvent*)theEvent wasKeyEquivalent:(BOOL)equiv; |
138 - (void)cancelChildPopups; | 138 - (void)cancelChildPopups; |
139 - (void)windowDidChangeBackingProperties:(NSNotification*)notification; | 139 - (void)windowDidChangeBackingProperties:(NSNotification*)notification; |
140 - (void)windowChangedScreen:(NSNotification*)notification; | 140 - (void)windowChangedScreen:(NSNotification*)notification; |
141 - (void)checkForPluginImeCancellation; | 141 - (void)checkForPluginImeCancellation; |
142 - (void)updateTabBackingStoreScaleFactor; | 142 - (void)updateTabBackingStoreScaleFactor; |
143 - (NSRect)firstViewRectForCharacterRange:(NSRange)theRange | |
144 actualRange:(NSRangePointer)actualRange; | |
143 @end | 145 @end |
144 | 146 |
145 // NSEvent subtype for scroll gestures events. | 147 // NSEvent subtype for scroll gestures events. |
146 static const short kIOHIDEventTypeScroll = 6; | 148 static const short kIOHIDEventTypeScroll = 6; |
147 | 149 |
148 // A window subclass that allows the fullscreen window to become main and gain | 150 // A window subclass that allows the fullscreen window to become main and gain |
149 // keyboard focus. This is only used for pepper flash. Normal fullscreen is | 151 // keyboard focus. This is only used for pepper flash. Normal fullscreen is |
150 // handled by the browser. | 152 // handled by the browser. |
151 @interface PepperFlashFullscreenWindow : UnderlayOpenGLHostingWindow | 153 @interface PepperFlashFullscreenWindow : UnderlayOpenGLHostingWindow |
152 @end | 154 @end |
(...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
747 } | 749 } |
748 | 750 |
749 // | 751 // |
750 // RenderWidgetHostViewCocoa uses the stored selection text, | 752 // RenderWidgetHostViewCocoa uses the stored selection text, |
751 // which implements NSServicesRequests protocol. | 753 // which implements NSServicesRequests protocol. |
752 // | 754 // |
753 void RenderWidgetHostViewMac::SelectionChanged(const string16& text, | 755 void RenderWidgetHostViewMac::SelectionChanged(const string16& text, |
754 size_t offset, | 756 size_t offset, |
755 const ui::Range& range) { | 757 const ui::Range& range) { |
756 if (range.is_empty() || text.empty()) { | 758 if (range.is_empty() || text.empty()) { |
757 selected_text_.clear(); | 759 selected_text_.clear(); |
758 } else { | 760 } else { |
759 size_t pos = range.GetMin() - offset; | 761 size_t pos = range.GetMin() - offset; |
760 size_t n = range.length(); | 762 size_t n = range.length(); |
761 | 763 |
762 DCHECK(pos + n <= text.length()) << "The text can not fully cover range."; | 764 DCHECK(pos + n <= text.length()) << "The text can not fully cover range."; |
763 if (pos >= text.length()) { | 765 if (pos >= text.length()) { |
764 DCHECK(false) << "The text can not cover range."; | 766 DCHECK(false) << "The text can not cover range."; |
765 return; | 767 return; |
766 } | 768 } |
767 selected_text_ = UTF16ToUTF8(text.substr(pos, n)); | 769 selected_text_ = UTF16ToUTF8(text.substr(pos, n)); |
768 } | 770 } |
769 | 771 |
770 [cocoa_view_ setSelectedRange:range.ToNSRange()]; | 772 [cocoa_view_ setSelectedRange:range.ToNSRange()]; |
771 // Updaes markedRange when there is no marked text so that retrieving | 773 // Updates markedRange when there is no marked text so that retrieving |
772 // markedRange immediately after calling setMarkdText: returns the current | 774 // markedRange immediately after calling setMarkdText: returns the current |
773 // caret position. | 775 // caret position. |
774 if (![cocoa_view_ hasMarkedText]) { | 776 if (![cocoa_view_ hasMarkedText]) { |
775 [cocoa_view_ setMarkedRange:range.ToNSRange()]; | 777 [cocoa_view_ setMarkedRange:range.ToNSRange()]; |
776 } | 778 } |
777 | 779 |
778 RenderWidgetHostViewBase::SelectionChanged(text, offset, range); | 780 RenderWidgetHostViewBase::SelectionChanged(text, offset, range); |
779 } | 781 } |
780 | 782 |
781 void RenderWidgetHostViewMac::SetShowingContextMenu(bool showing) { | 783 void RenderWidgetHostViewMac::SetShowingContextMenu(bool showing) { |
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1393 } | 1395 } |
1394 | 1396 |
1395 void RenderWidgetHostViewMac::WindowFrameChanged() { | 1397 void RenderWidgetHostViewMac::WindowFrameChanged() { |
1396 if (render_widget_host_) { | 1398 if (render_widget_host_) { |
1397 render_widget_host_->Send(new ViewMsg_WindowFrameChanged( | 1399 render_widget_host_->Send(new ViewMsg_WindowFrameChanged( |
1398 render_widget_host_->GetRoutingID(), GetBoundsInRootWindow(), | 1400 render_widget_host_->GetRoutingID(), GetBoundsInRootWindow(), |
1399 GetViewBounds())); | 1401 GetViewBounds())); |
1400 } | 1402 } |
1401 } | 1403 } |
1402 | 1404 |
1405 void RenderWidgetHostViewMac::ShowDefinitionForSelection() { | |
1406 // Brings up either Dictionary.app or a light-weight dictionary panel, | |
1407 // depending on system settings. | |
1408 NSRange selection_range = [cocoa_view_ selectedRange]; | |
1409 NSAttributedString* attr_string = | |
1410 [cocoa_view_ attributedSubstringForProposedRange:selection_range | |
1411 actualRange:nil]; | |
1412 NSRect rect = [cocoa_view_ firstViewRectForCharacterRange:selection_range | |
1413 actualRange:nil]; | |
1414 | |
1415 // Set |rect.origin| to the text baseline based on |attr_string|'s font. | |
Avi (use Gerrit)
2012/08/07 14:18:30
Nice cheat! Can you acknowledge in the comment tha
| |
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 | |
1403 void RenderWidgetHostViewMac::SetBackground(const SkBitmap& background) { | 1423 void RenderWidgetHostViewMac::SetBackground(const SkBitmap& background) { |
1404 RenderWidgetHostViewBase::SetBackground(background); | 1424 RenderWidgetHostViewBase::SetBackground(background); |
1405 if (render_widget_host_) | 1425 if (render_widget_host_) |
1406 render_widget_host_->Send(new ViewMsg_SetBackground( | 1426 render_widget_host_->Send(new ViewMsg_SetBackground( |
1407 render_widget_host_->GetRoutingID(), background)); | 1427 render_widget_host_->GetRoutingID(), background)); |
1408 } | 1428 } |
1409 | 1429 |
1410 void RenderWidgetHostViewMac::OnAccessibilityNotifications( | 1430 void RenderWidgetHostViewMac::OnAccessibilityNotifications( |
1411 const std::vector<AccessibilityHostMsg_NotificationParams>& params) { | 1431 const std::vector<AccessibilityHostMsg_NotificationParams>& params) { |
1412 if (!GetBrowserAccessibilityManager()) { | 1432 if (!GetBrowserAccessibilityManager()) { |
(...skipping 1377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2790 thePoint = [self convertPoint:thePoint fromView:nil]; | 2810 thePoint = [self convertPoint:thePoint fromView:nil]; |
2791 thePoint.y = NSHeight([self frame]) - thePoint.y; | 2811 thePoint.y = NSHeight([self frame]) - thePoint.y; |
2792 | 2812 |
2793 NSUInteger index = | 2813 NSUInteger index = |
2794 TextInputClientMac::GetInstance()->GetCharacterIndexAtPoint( | 2814 TextInputClientMac::GetInstance()->GetCharacterIndexAtPoint( |
2795 renderWidgetHostView_->render_widget_host_, | 2815 renderWidgetHostView_->render_widget_host_, |
2796 gfx::Point(thePoint.x, thePoint.y)); | 2816 gfx::Point(thePoint.x, thePoint.y)); |
2797 return index; | 2817 return index; |
2798 } | 2818 } |
2799 | 2819 |
2800 - (NSRect)firstRectForCharacterRange:(NSRange)theRange | 2820 - (NSRect)firstViewRectForCharacterRange:(NSRange)theRange |
2801 actualRange:(NSRangePointer)actualRange { | 2821 actualRange:(NSRangePointer)actualRange { |
2802 NSRect rect; | 2822 NSRect rect; |
2803 if (!renderWidgetHostView_->GetCachedFirstRectForCharacterRange( | 2823 if (!renderWidgetHostView_->GetCachedFirstRectForCharacterRange( |
2804 theRange, | 2824 theRange, |
2805 &rect, | 2825 &rect, |
2806 actualRange)) { | 2826 actualRange)) { |
2807 rect = TextInputClientMac::GetInstance()->GetFirstRectForRange( | 2827 rect = TextInputClientMac::GetInstance()->GetFirstRectForRange( |
2808 renderWidgetHostView_->render_widget_host_, theRange); | 2828 renderWidgetHostView_->render_widget_host_, theRange); |
2809 | 2829 |
2810 // TODO(thakis): Pipe |actualRange| through TextInputClientMac machinery. | 2830 // TODO(thakis): Pipe |actualRange| through TextInputClientMac machinery. |
2811 if (actualRange) | 2831 if (actualRange) |
2812 *actualRange = theRange; | 2832 *actualRange = theRange; |
2813 } | 2833 } |
2814 | 2834 |
2815 // The returned rectangle is in WebKit coordinates (upper left origin), so | 2835 // The returned rectangle is in WebKit coordinates (upper left origin), so |
2816 // flip the coordinate system and then convert it into screen coordinates for | 2836 // flip the coordinate system. |
2817 // return. | |
2818 NSRect viewFrame = [self frame]; | 2837 NSRect viewFrame = [self frame]; |
2819 rect.origin.y = NSHeight(viewFrame) - NSMaxY(rect); | 2838 rect.origin.y = NSHeight(viewFrame) - NSMaxY(rect); |
2839 return rect; | |
2840 } | |
2841 | |
2842 - (NSRect)firstRectForCharacterRange:(NSRange)theRange | |
2843 actualRange:(NSRangePointer)actualRange { | |
2844 NSRect rect = [self firstViewRectForCharacterRange:theRange | |
2845 actualRange:actualRange]; | |
2846 | |
2847 // Convert into screen coordinates for return. | |
2820 rect = [self convertRect:rect toView:nil]; | 2848 rect = [self convertRect:rect toView:nil]; |
2821 rect.origin = [[self window] convertBaseToScreen:rect.origin]; | 2849 rect.origin = [[self window] convertBaseToScreen:rect.origin]; |
2822 return rect; | 2850 return rect; |
2823 } | 2851 } |
2824 | 2852 |
2825 - (NSRange)markedRange { | 2853 - (NSRange)markedRange { |
2826 // An input method calls this method to check if an application really has | 2854 // An input method calls this method to check if an application really has |
2827 // a text being composed when hasMarkedText call returns true. | 2855 // a text being composed when hasMarkedText call returns true. |
2828 // Returns the range saved in the setMarkedText method so the input method | 2856 // Returns the range saved in the setMarkedText method so the input method |
2829 // calls the setMarkedText method and we can update the composition node | 2857 // calls the setMarkedText method and we can update the composition node |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3215 if (!string) return NO; | 3243 if (!string) return NO; |
3216 | 3244 |
3217 // If the user is currently using an IME, confirm the IME input, | 3245 // If the user is currently using an IME, confirm the IME input, |
3218 // and then insert the text from the service, the same as TextEdit and Safari. | 3246 // and then insert the text from the service, the same as TextEdit and Safari. |
3219 [self confirmComposition]; | 3247 [self confirmComposition]; |
3220 [self insertText:string]; | 3248 [self insertText:string]; |
3221 return YES; | 3249 return YES; |
3222 } | 3250 } |
3223 | 3251 |
3224 @end | 3252 @end |
OLD | NEW |