| 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 #import <objc/runtime.h> | 7 #import <objc/runtime.h> |
| 8 #include <OpenGL/gl.h> | 8 #include <OpenGL/gl.h> |
| 9 #include <QuartzCore/QuartzCore.h> | 9 #include <QuartzCore/QuartzCore.h> |
| 10 #include <stdint.h> | 10 #include <stdint.h> |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 #include "content/public/browser/browser_thread.h" | 64 #include "content/public/browser/browser_thread.h" |
| 65 #include "content/public/browser/native_web_keyboard_event.h" | 65 #include "content/public/browser/native_web_keyboard_event.h" |
| 66 #include "content/public/browser/render_widget_host_view_frame_subscriber.h" | 66 #include "content/public/browser/render_widget_host_view_frame_subscriber.h" |
| 67 #import "content/public/browser/render_widget_host_view_mac_delegate.h" | 67 #import "content/public/browser/render_widget_host_view_mac_delegate.h" |
| 68 #include "content/public/browser/web_contents.h" | 68 #include "content/public/browser/web_contents.h" |
| 69 #include "gpu/ipc/common/gpu_messages.h" | 69 #include "gpu/ipc/common/gpu_messages.h" |
| 70 #include "skia/ext/platform_canvas.h" | 70 #include "skia/ext/platform_canvas.h" |
| 71 #include "skia/ext/skia_utils_mac.h" | 71 #include "skia/ext/skia_utils_mac.h" |
| 72 #include "third_party/WebKit/public/platform/WebScreenInfo.h" | 72 #include "third_party/WebKit/public/platform/WebScreenInfo.h" |
| 73 #include "third_party/WebKit/public/web/WebInputEvent.h" | 73 #include "third_party/WebKit/public/web/WebInputEvent.h" |
| 74 #import "third_party/mozilla/ComplexTextInputPanel.h" | |
| 75 #import "ui/base/clipboard/clipboard_util_mac.h" | 74 #import "ui/base/clipboard/clipboard_util_mac.h" |
| 76 #include "ui/base/cocoa/animation_utils.h" | 75 #include "ui/base/cocoa/animation_utils.h" |
| 77 #include "ui/base/cocoa/cocoa_base_utils.h" | 76 #include "ui/base/cocoa/cocoa_base_utils.h" |
| 78 #import "ui/base/cocoa/fullscreen_window_manager.h" | 77 #import "ui/base/cocoa/fullscreen_window_manager.h" |
| 79 #import "ui/base/cocoa/underlay_opengl_hosting_window.h" | 78 #import "ui/base/cocoa/underlay_opengl_hosting_window.h" |
| 80 #include "ui/base/layout.h" | 79 #include "ui/base/layout.h" |
| 81 #include "ui/compositor/compositor.h" | 80 #include "ui/compositor/compositor.h" |
| 82 #include "ui/compositor/layer.h" | 81 #include "ui/compositor/layer.h" |
| 83 #include "ui/events/keycodes/keyboard_codes.h" | 82 #include "ui/events/keycodes/keyboard_codes.h" |
| 84 #include "ui/gfx/color_profile.h" | 83 #include "ui/gfx/color_profile.h" |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 - (void)processedWheelEvent:(const blink::WebMouseWheelEvent&)event | 179 - (void)processedWheelEvent:(const blink::WebMouseWheelEvent&)event |
| 181 consumed:(BOOL)consumed; | 180 consumed:(BOOL)consumed; |
| 182 - (void)processedGestureScrollEvent:(const blink::WebGestureEvent&)event | 181 - (void)processedGestureScrollEvent:(const blink::WebGestureEvent&)event |
| 183 consumed:(BOOL)consumed; | 182 consumed:(BOOL)consumed; |
| 184 | 183 |
| 185 - (void)keyEvent:(NSEvent*)theEvent wasKeyEquivalent:(BOOL)equiv; | 184 - (void)keyEvent:(NSEvent*)theEvent wasKeyEquivalent:(BOOL)equiv; |
| 186 - (void)windowDidChangeBackingProperties:(NSNotification*)notification; | 185 - (void)windowDidChangeBackingProperties:(NSNotification*)notification; |
| 187 - (void)windowChangedGlobalFrame:(NSNotification*)notification; | 186 - (void)windowChangedGlobalFrame:(NSNotification*)notification; |
| 188 - (void)windowDidBecomeKey:(NSNotification*)notification; | 187 - (void)windowDidBecomeKey:(NSNotification*)notification; |
| 189 - (void)windowDidResignKey:(NSNotification*)notification; | 188 - (void)windowDidResignKey:(NSNotification*)notification; |
| 190 - (void)checkForPluginImeCancellation; | |
| 191 - (void)updateScreenProperties; | 189 - (void)updateScreenProperties; |
| 192 - (void)setResponderDelegate: | 190 - (void)setResponderDelegate: |
| 193 (NSObject<RenderWidgetHostViewMacDelegate>*)delegate; | 191 (NSObject<RenderWidgetHostViewMacDelegate>*)delegate; |
| 194 - (void)showLookUpDictionaryOverlayInternal:(NSAttributedString*) string | 192 - (void)showLookUpDictionaryOverlayInternal:(NSAttributedString*) string |
| 195 baselinePoint:(NSPoint) baselinePoint | 193 baselinePoint:(NSPoint) baselinePoint |
| 196 targetView:(NSView*) view; | 194 targetView:(NSView*) view; |
| 197 @end | 195 @end |
| 198 | 196 |
| 199 // A window subclass that allows the fullscreen window to become main and gain | 197 // A window subclass that allows the fullscreen window to become main and gain |
| 200 // keyboard focus. This is only used for pepper flash. Normal fullscreen is | 198 // keyboard focus. This is only used for pepper flash. Normal fullscreen is |
| (...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 680 return; | 678 return; |
| 681 | 679 |
| 682 // This should only be reached if |render_widget_host_| is hidden, destroyed, | 680 // This should only be reached if |render_widget_host_| is hidden, destroyed, |
| 683 // or in the process of being destroyed. | 681 // or in the process of being destroyed. |
| 684 DestroyBrowserCompositorView(); | 682 DestroyBrowserCompositorView(); |
| 685 } | 683 } |
| 686 | 684 |
| 687 bool RenderWidgetHostViewMac::OnMessageReceived(const IPC::Message& message) { | 685 bool RenderWidgetHostViewMac::OnMessageReceived(const IPC::Message& message) { |
| 688 bool handled = true; | 686 bool handled = true; |
| 689 IPC_BEGIN_MESSAGE_MAP(RenderWidgetHostViewMac, message) | 687 IPC_BEGIN_MESSAGE_MAP(RenderWidgetHostViewMac, message) |
| 690 IPC_MESSAGE_HANDLER(ViewHostMsg_PluginFocusChanged, OnPluginFocusChanged) | |
| 691 IPC_MESSAGE_HANDLER(ViewHostMsg_StartPluginIme, OnStartPluginIme) | |
| 692 IPC_MESSAGE_HANDLER(ViewMsg_GetRenderedTextCompleted, | 688 IPC_MESSAGE_HANDLER(ViewMsg_GetRenderedTextCompleted, |
| 693 OnGetRenderedTextCompleted) | 689 OnGetRenderedTextCompleted) |
| 694 IPC_MESSAGE_UNHANDLED(handled = false) | 690 IPC_MESSAGE_UNHANDLED(handled = false) |
| 695 IPC_END_MESSAGE_MAP() | 691 IPC_END_MESSAGE_MAP() |
| 696 return handled; | 692 return handled; |
| 697 } | 693 } |
| 698 | 694 |
| 699 void RenderWidgetHostViewMac::InitAsChild( | 695 void RenderWidgetHostViewMac::InitAsChild( |
| 700 gfx::NativeView parent_view) { | 696 gfx::NativeView parent_view) { |
| 701 } | 697 } |
| (...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1265 | 1261 |
| 1266 void RenderWidgetHostViewMac::KillSelf() { | 1262 void RenderWidgetHostViewMac::KillSelf() { |
| 1267 if (!weak_factory_.HasWeakPtrs()) { | 1263 if (!weak_factory_.HasWeakPtrs()) { |
| 1268 [cocoa_view_ setHidden:YES]; | 1264 [cocoa_view_ setHidden:YES]; |
| 1269 base::MessageLoop::current()->PostTask(FROM_HERE, | 1265 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 1270 base::Bind(&RenderWidgetHostViewMac::ShutdownHost, | 1266 base::Bind(&RenderWidgetHostViewMac::ShutdownHost, |
| 1271 weak_factory_.GetWeakPtr())); | 1267 weak_factory_.GetWeakPtr())); |
| 1272 } | 1268 } |
| 1273 } | 1269 } |
| 1274 | 1270 |
| 1275 bool RenderWidgetHostViewMac::PostProcessEventForPluginIme( | |
| 1276 const NativeWebKeyboardEvent& event) { | |
| 1277 // Check WebInputEvent type since multiple types of events can be sent into | |
| 1278 // WebKit for the same OS event (e.g., RawKeyDown and Char), so filtering is | |
| 1279 // necessary to avoid double processing. | |
| 1280 // Also check the native type, since NSFlagsChanged is considered a key event | |
| 1281 // for WebKit purposes, but isn't considered a key event by the OS. | |
| 1282 if (event.type == WebInputEvent::RawKeyDown && | |
| 1283 [event.os_event type] == NSKeyDown) | |
| 1284 return [cocoa_view_ postProcessEventForPluginIme:event.os_event]; | |
| 1285 return false; | |
| 1286 } | |
| 1287 | |
| 1288 void RenderWidgetHostViewMac::PluginImeCompositionCompleted( | |
| 1289 const base::string16& text, int plugin_id) { | |
| 1290 if (render_widget_host_) { | |
| 1291 render_widget_host_->Send(new ViewMsg_PluginImeCompositionCompleted( | |
| 1292 render_widget_host_->GetRoutingID(), text, plugin_id)); | |
| 1293 } | |
| 1294 } | |
| 1295 | |
| 1296 bool RenderWidgetHostViewMac::GetLineBreakIndex( | 1271 bool RenderWidgetHostViewMac::GetLineBreakIndex( |
| 1297 const std::vector<gfx::Rect>& bounds, | 1272 const std::vector<gfx::Rect>& bounds, |
| 1298 const gfx::Range& range, | 1273 const gfx::Range& range, |
| 1299 size_t* line_break_point) { | 1274 size_t* line_break_point) { |
| 1300 DCHECK(line_break_point); | 1275 DCHECK(line_break_point); |
| 1301 if (range.start() >= bounds.size() || range.is_reversed() || range.is_empty()) | 1276 if (range.start() >= bounds.size() || range.is_reversed() || range.is_empty()) |
| 1302 return false; | 1277 return false; |
| 1303 | 1278 |
| 1304 // We can't check line breaking completely from only rectangle array. Thus we | 1279 // We can't check line breaking completely from only rectangle array. Thus we |
| 1305 // assume the line breaking as the next character's y offset is larger than | 1280 // assume the line breaking as the next character's y offset is larger than |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1682 render_widget_host_->SetActive(active); | 1657 render_widget_host_->SetActive(active); |
| 1683 if (active) { | 1658 if (active) { |
| 1684 if (HasFocus()) | 1659 if (HasFocus()) |
| 1685 render_widget_host_->Focus(); | 1660 render_widget_host_->Focus(); |
| 1686 } else { | 1661 } else { |
| 1687 render_widget_host_->Blur(); | 1662 render_widget_host_->Blur(); |
| 1688 } | 1663 } |
| 1689 } | 1664 } |
| 1690 if (HasFocus()) | 1665 if (HasFocus()) |
| 1691 SetTextInputActive(active); | 1666 SetTextInputActive(active); |
| 1692 if (!active) { | 1667 if (!active) |
| 1693 [cocoa_view_ setPluginImeActive:NO]; | |
| 1694 UnlockMouse(); | 1668 UnlockMouse(); |
| 1695 } | |
| 1696 } | |
| 1697 | |
| 1698 void RenderWidgetHostViewMac::SetWindowVisibility(bool visible) { | |
| 1699 if (render_widget_host_) { | |
| 1700 render_widget_host_->Send(new ViewMsg_SetWindowVisibility( | |
| 1701 render_widget_host_->GetRoutingID(), visible)); | |
| 1702 } | |
| 1703 } | |
| 1704 | |
| 1705 void RenderWidgetHostViewMac::WindowFrameChanged() { | |
| 1706 if (render_widget_host_) { | |
| 1707 render_widget_host_->Send(new ViewMsg_WindowFrameChanged( | |
| 1708 render_widget_host_->GetRoutingID(), GetBoundsInRootWindow(), | |
| 1709 GetViewBounds())); | |
| 1710 } | |
| 1711 } | 1669 } |
| 1712 | 1670 |
| 1713 void RenderWidgetHostViewMac::ShowDefinitionForSelection() { | 1671 void RenderWidgetHostViewMac::ShowDefinitionForSelection() { |
| 1714 RenderWidgetHostViewMacDictionaryHelper helper(this); | 1672 RenderWidgetHostViewMacDictionaryHelper helper(this); |
| 1715 helper.ShowDefinitionForSelection(); | 1673 helper.ShowDefinitionForSelection(); |
| 1716 } | 1674 } |
| 1717 | 1675 |
| 1718 void RenderWidgetHostViewMac::SetBackgroundColor(SkColor color) { | 1676 void RenderWidgetHostViewMac::SetBackgroundColor(SkColor color) { |
| 1719 if (color == background_color_) | 1677 if (color == background_color_) |
| 1720 return; | 1678 return; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1761 if (text_input_type_ == ui::TEXT_INPUT_TYPE_PASSWORD) | 1719 if (text_input_type_ == ui::TEXT_INPUT_TYPE_PASSWORD) |
| 1762 EnablePasswordInput(); | 1720 EnablePasswordInput(); |
| 1763 else | 1721 else |
| 1764 DisablePasswordInput(); | 1722 DisablePasswordInput(); |
| 1765 } else { | 1723 } else { |
| 1766 if (text_input_type_ == ui::TEXT_INPUT_TYPE_PASSWORD) | 1724 if (text_input_type_ == ui::TEXT_INPUT_TYPE_PASSWORD) |
| 1767 DisablePasswordInput(); | 1725 DisablePasswordInput(); |
| 1768 } | 1726 } |
| 1769 } | 1727 } |
| 1770 | 1728 |
| 1771 void RenderWidgetHostViewMac::OnPluginFocusChanged(bool focused, | |
| 1772 int plugin_id) { | |
| 1773 [cocoa_view_ pluginFocusChanged:(focused ? YES : NO) forPlugin:plugin_id]; | |
| 1774 } | |
| 1775 | |
| 1776 void RenderWidgetHostViewMac::OnStartPluginIme() { | |
| 1777 [cocoa_view_ setPluginImeActive:YES]; | |
| 1778 } | |
| 1779 | |
| 1780 void RenderWidgetHostViewMac::OnGetRenderedTextCompleted( | 1729 void RenderWidgetHostViewMac::OnGetRenderedTextCompleted( |
| 1781 const std::string& text) { | 1730 const std::string& text) { |
| 1782 SpeakText(text); | 1731 SpeakText(text); |
| 1783 } | 1732 } |
| 1784 | 1733 |
| 1785 void RenderWidgetHostViewMac::PauseForPendingResizeOrRepaintsAndDraw() { | 1734 void RenderWidgetHostViewMac::PauseForPendingResizeOrRepaintsAndDraw() { |
| 1786 if (!render_widget_host_ || render_widget_host_->is_hidden()) | 1735 if (!render_widget_host_ || render_widget_host_->is_hidden()) |
| 1787 return; | 1736 return; |
| 1788 | 1737 |
| 1789 // Pausing for one view prevents others from receiving frames. | 1738 // Pausing for one view prevents others from receiving frames. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1825 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r { | 1774 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r { |
| 1826 self = [super initWithFrame:NSZeroRect]; | 1775 self = [super initWithFrame:NSZeroRect]; |
| 1827 if (self) { | 1776 if (self) { |
| 1828 self.acceptsTouchEvents = YES; | 1777 self.acceptsTouchEvents = YES; |
| 1829 editCommand_helper_.reset(new RenderWidgetHostViewMacEditCommandHelper); | 1778 editCommand_helper_.reset(new RenderWidgetHostViewMacEditCommandHelper); |
| 1830 editCommand_helper_->AddEditingSelectorsToClass([self class]); | 1779 editCommand_helper_->AddEditingSelectorsToClass([self class]); |
| 1831 | 1780 |
| 1832 renderWidgetHostView_.reset(r); | 1781 renderWidgetHostView_.reset(r); |
| 1833 canBeKeyView_ = YES; | 1782 canBeKeyView_ = YES; |
| 1834 opaque_ = YES; | 1783 opaque_ = YES; |
| 1835 focusedPluginIdentifier_ = -1; | |
| 1836 pinchHasReachedZoomThreshold_ = false; | 1784 pinchHasReachedZoomThreshold_ = false; |
| 1837 | 1785 |
| 1838 // OpenGL support: | 1786 // OpenGL support: |
| 1839 if ([self respondsToSelector: | 1787 if ([self respondsToSelector: |
| 1840 @selector(setWantsBestResolutionOpenGLSurface:)]) { | 1788 @selector(setWantsBestResolutionOpenGLSurface:)]) { |
| 1841 [self setWantsBestResolutionOpenGLSurface:YES]; | 1789 [self setWantsBestResolutionOpenGLSurface:YES]; |
| 1842 } | 1790 } |
| 1843 [[NSNotificationCenter defaultCenter] | 1791 [[NSNotificationCenter defaultCenter] |
| 1844 addObserver:self | 1792 addObserver:self |
| 1845 selector:@selector(didChangeScreenParameters:) | 1793 selector:@selector(didChangeScreenParameters:) |
| (...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2201 // Clear them here so that we can know whether they have changed afterwards. | 2149 // Clear them here so that we can know whether they have changed afterwards. |
| 2202 textToBeInserted_.clear(); | 2150 textToBeInserted_.clear(); |
| 2203 markedText_.clear(); | 2151 markedText_.clear(); |
| 2204 markedTextSelectedRange_ = NSMakeRange(NSNotFound, 0); | 2152 markedTextSelectedRange_ = NSMakeRange(NSNotFound, 0); |
| 2205 underlines_.clear(); | 2153 underlines_.clear(); |
| 2206 setMarkedTextReplacementRange_ = gfx::Range::InvalidRange(); | 2154 setMarkedTextReplacementRange_ = gfx::Range::InvalidRange(); |
| 2207 unmarkTextCalled_ = NO; | 2155 unmarkTextCalled_ = NO; |
| 2208 hasEditCommands_ = NO; | 2156 hasEditCommands_ = NO; |
| 2209 editCommands_.clear(); | 2157 editCommands_.clear(); |
| 2210 | 2158 |
| 2211 // Before doing anything with a key down, check to see if plugin IME has been | |
| 2212 // cancelled, since the plugin host needs to be informed of that before | |
| 2213 // receiving the keydown. | |
| 2214 if ([theEvent type] == NSKeyDown) | |
| 2215 [self checkForPluginImeCancellation]; | |
| 2216 | |
| 2217 // Sends key down events to input method first, then we can decide what should | 2159 // Sends key down events to input method first, then we can decide what should |
| 2218 // be done according to input method's feedback. | 2160 // be done according to input method's feedback. |
| 2219 // If a plugin is active, bypass this step since events are forwarded directly | 2161 [self interpretKeyEvents:[NSArray arrayWithObject:theEvent]]; |
| 2220 // to the plugin IME. | |
| 2221 if (focusedPluginIdentifier_ == -1) | |
| 2222 [self interpretKeyEvents:[NSArray arrayWithObject:theEvent]]; | |
| 2223 | 2162 |
| 2224 handlingKeyDown_ = NO; | 2163 handlingKeyDown_ = NO; |
| 2225 | 2164 |
| 2226 // Indicates if we should send the key event and corresponding editor commands | 2165 // Indicates if we should send the key event and corresponding editor commands |
| 2227 // after processing the input method result. | 2166 // after processing the input method result. |
| 2228 BOOL delayEventUntilAfterImeCompostion = NO; | 2167 BOOL delayEventUntilAfterImeCompostion = NO; |
| 2229 | 2168 |
| 2230 // To emulate Windows, over-write |event.windowsKeyCode| to VK_PROCESSKEY | 2169 // To emulate Windows, over-write |event.windowsKeyCode| to VK_PROCESSKEY |
| 2231 // while an input method is composing or inserting a text. | 2170 // while an input method is composing or inserting a text. |
| 2232 // Gmail checks this code in its onkeydown handler to stop auto-completing | 2171 // Gmail checks this code in its onkeydown handler to stop auto-completing |
| (...skipping 882 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3115 } | 3054 } |
| 3116 | 3055 |
| 3117 - (NSInteger)conversationIdentifier { | 3056 - (NSInteger)conversationIdentifier { |
| 3118 return reinterpret_cast<NSInteger>(self); | 3057 return reinterpret_cast<NSInteger>(self); |
| 3119 } | 3058 } |
| 3120 | 3059 |
| 3121 // Each RenderWidgetHostViewCocoa has its own input context, but we return | 3060 // Each RenderWidgetHostViewCocoa has its own input context, but we return |
| 3122 // nil when the caret is in non-editable content or password box to avoid | 3061 // nil when the caret is in non-editable content or password box to avoid |
| 3123 // making input methods do their work. | 3062 // making input methods do their work. |
| 3124 - (NSTextInputContext *)inputContext { | 3063 - (NSTextInputContext *)inputContext { |
| 3125 if (focusedPluginIdentifier_ != -1) | |
| 3126 return [[ComplexTextInputPanel sharedComplexTextInputPanel] inputContext]; | |
| 3127 | |
| 3128 switch(renderWidgetHostView_->text_input_type_) { | 3064 switch(renderWidgetHostView_->text_input_type_) { |
| 3129 case ui::TEXT_INPUT_TYPE_NONE: | 3065 case ui::TEXT_INPUT_TYPE_NONE: |
| 3130 case ui::TEXT_INPUT_TYPE_PASSWORD: | 3066 case ui::TEXT_INPUT_TYPE_PASSWORD: |
| 3131 return nil; | 3067 return nil; |
| 3132 default: | 3068 default: |
| 3133 return [super inputContext]; | 3069 return [super inputContext]; |
| 3134 } | 3070 } |
| 3135 } | 3071 } |
| 3136 | 3072 |
| 3137 - (BOOL)hasMarkedText { | 3073 - (BOOL)hasMarkedText { |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3270 | 3206 |
| 3271 - (void)viewDidMoveToWindow { | 3207 - (void)viewDidMoveToWindow { |
| 3272 if ([self window]) { | 3208 if ([self window]) { |
| 3273 [self updateScreenProperties]; | 3209 [self updateScreenProperties]; |
| 3274 } else { | 3210 } else { |
| 3275 // If the RenderWidgetHostViewCocoa is being removed from its window, tear | 3211 // If the RenderWidgetHostViewCocoa is being removed from its window, tear |
| 3276 // down its browser compositor resources, if needed. | 3212 // down its browser compositor resources, if needed. |
| 3277 renderWidgetHostView_->DestroySuspendedBrowserCompositorViewIfNeeded(); | 3213 renderWidgetHostView_->DestroySuspendedBrowserCompositorViewIfNeeded(); |
| 3278 } | 3214 } |
| 3279 | 3215 |
| 3280 if (canBeKeyView_) { | |
| 3281 NSWindow* newWindow = [self window]; | |
| 3282 // Pointer comparison only, since we don't know if lastWindow_ is still | |
| 3283 // valid. | |
| 3284 if (newWindow) { | |
| 3285 // If we move into a new window, refresh the frame information. We | |
| 3286 // don't need to do it if it was the same window as it used to be in, | |
| 3287 // since that case is covered by WasShown(). We only want to do this for | |
| 3288 // real browser views, not popups. | |
| 3289 if (newWindow != lastWindow_) { | |
| 3290 lastWindow_ = newWindow; | |
| 3291 renderWidgetHostView_->WindowFrameChanged(); | |
| 3292 } | |
| 3293 } | |
| 3294 } | |
| 3295 | |
| 3296 // If we switch windows (or are removed from the view hierarchy), cancel any | 3216 // If we switch windows (or are removed from the view hierarchy), cancel any |
| 3297 // open mouse-downs. | 3217 // open mouse-downs. |
| 3298 if (hasOpenMouseDown_) { | 3218 if (hasOpenMouseDown_) { |
| 3299 WebMouseEvent event; | 3219 WebMouseEvent event; |
| 3300 event.type = WebInputEvent::MouseUp; | 3220 event.type = WebInputEvent::MouseUp; |
| 3301 event.button = WebMouseEvent::ButtonLeft; | 3221 event.button = WebMouseEvent::ButtonLeft; |
| 3302 renderWidgetHostView_->ForwardMouseEvent(event); | 3222 renderWidgetHostView_->ForwardMouseEvent(event); |
| 3303 | 3223 |
| 3304 hasOpenMouseDown_ = NO; | 3224 hasOpenMouseDown_ = NO; |
| 3305 } | 3225 } |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3397 if (!hasMarkedText_) | 3317 if (!hasMarkedText_) |
| 3398 return; | 3318 return; |
| 3399 | 3319 |
| 3400 if (renderWidgetHostView_->render_widget_host_) | 3320 if (renderWidgetHostView_->render_widget_host_) |
| 3401 renderWidgetHostView_->render_widget_host_->ImeConfirmComposition( | 3321 renderWidgetHostView_->render_widget_host_->ImeConfirmComposition( |
| 3402 base::string16(), gfx::Range::InvalidRange(), false); | 3322 base::string16(), gfx::Range::InvalidRange(), false); |
| 3403 | 3323 |
| 3404 [self cancelComposition]; | 3324 [self cancelComposition]; |
| 3405 } | 3325 } |
| 3406 | 3326 |
| 3407 - (void)setPluginImeActive:(BOOL)active { | |
| 3408 if (active == pluginImeActive_) | |
| 3409 return; | |
| 3410 | |
| 3411 pluginImeActive_ = active; | |
| 3412 if (!active) { | |
| 3413 [[ComplexTextInputPanel sharedComplexTextInputPanel] cancelComposition]; | |
| 3414 renderWidgetHostView_->PluginImeCompositionCompleted( | |
| 3415 base::string16(), focusedPluginIdentifier_); | |
| 3416 } | |
| 3417 } | |
| 3418 | |
| 3419 - (void)pluginFocusChanged:(BOOL)focused forPlugin:(int)pluginId { | |
| 3420 if (focused) | |
| 3421 focusedPluginIdentifier_ = pluginId; | |
| 3422 else if (focusedPluginIdentifier_ == pluginId) | |
| 3423 focusedPluginIdentifier_ = -1; | |
| 3424 | |
| 3425 // Whenever plugin focus changes, plugin IME resets. | |
| 3426 [self setPluginImeActive:NO]; | |
| 3427 } | |
| 3428 | |
| 3429 - (BOOL)postProcessEventForPluginIme:(NSEvent*)event { | |
| 3430 if (!pluginImeActive_) | |
| 3431 return false; | |
| 3432 | |
| 3433 ComplexTextInputPanel* inputPanel = | |
| 3434 [ComplexTextInputPanel sharedComplexTextInputPanel]; | |
| 3435 NSString* composited_string = nil; | |
| 3436 BOOL handled = [inputPanel interpretKeyEvent:event | |
| 3437 string:&composited_string]; | |
| 3438 if (composited_string) { | |
| 3439 renderWidgetHostView_->PluginImeCompositionCompleted( | |
| 3440 base::SysNSStringToUTF16(composited_string), focusedPluginIdentifier_); | |
| 3441 pluginImeActive_ = NO; | |
| 3442 } | |
| 3443 return handled; | |
| 3444 } | |
| 3445 | |
| 3446 - (void)checkForPluginImeCancellation { | |
| 3447 if (pluginImeActive_ && | |
| 3448 ![[ComplexTextInputPanel sharedComplexTextInputPanel] inComposition]) { | |
| 3449 renderWidgetHostView_->PluginImeCompositionCompleted( | |
| 3450 base::string16(), focusedPluginIdentifier_); | |
| 3451 pluginImeActive_ = NO; | |
| 3452 } | |
| 3453 } | |
| 3454 | |
| 3455 // Overriding a NSResponder method to support application services. | 3327 // Overriding a NSResponder method to support application services. |
| 3456 | 3328 |
| 3457 - (id)validRequestorForSendType:(NSString*)sendType | 3329 - (id)validRequestorForSendType:(NSString*)sendType |
| 3458 returnType:(NSString*)returnType { | 3330 returnType:(NSString*)returnType { |
| 3459 id requestor = nil; | 3331 id requestor = nil; |
| 3460 BOOL sendTypeIsString = [sendType isEqual:NSStringPboardType]; | 3332 BOOL sendTypeIsString = [sendType isEqual:NSStringPboardType]; |
| 3461 BOOL returnTypeIsString = [returnType isEqual:NSStringPboardType]; | 3333 BOOL returnTypeIsString = [returnType isEqual:NSStringPboardType]; |
| 3462 BOOL hasText = !renderWidgetHostView_->selected_text().empty(); | 3334 BOOL hasText = !renderWidgetHostView_->selected_text().empty(); |
| 3463 BOOL takesText = | 3335 BOOL takesText = |
| 3464 renderWidgetHostView_->text_input_type_ != ui::TEXT_INPUT_TYPE_NONE; | 3336 renderWidgetHostView_->text_input_type_ != ui::TEXT_INPUT_TYPE_NONE; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3524 | 3396 |
| 3525 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding | 3397 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding |
| 3526 // regions that are not draggable. (See ControlRegionView in | 3398 // regions that are not draggable. (See ControlRegionView in |
| 3527 // native_app_window_cocoa.mm). This requires the render host view to be | 3399 // native_app_window_cocoa.mm). This requires the render host view to be |
| 3528 // draggable by default. | 3400 // draggable by default. |
| 3529 - (BOOL)mouseDownCanMoveWindow { | 3401 - (BOOL)mouseDownCanMoveWindow { |
| 3530 return YES; | 3402 return YES; |
| 3531 } | 3403 } |
| 3532 | 3404 |
| 3533 @end | 3405 @end |
| OLD | NEW |