Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(105)

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_mac.mm

Issue 1858063002: Remove Mac NPAPI things (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 1180 matching lines...) Expand 10 before | Expand all | Expand 10 after
1265 1264
1266 void RenderWidgetHostViewMac::KillSelf() { 1265 void RenderWidgetHostViewMac::KillSelf() {
1267 if (!weak_factory_.HasWeakPtrs()) { 1266 if (!weak_factory_.HasWeakPtrs()) {
1268 [cocoa_view_ setHidden:YES]; 1267 [cocoa_view_ setHidden:YES];
1269 base::MessageLoop::current()->PostTask(FROM_HERE, 1268 base::MessageLoop::current()->PostTask(FROM_HERE,
1270 base::Bind(&RenderWidgetHostViewMac::ShutdownHost, 1269 base::Bind(&RenderWidgetHostViewMac::ShutdownHost,
1271 weak_factory_.GetWeakPtr())); 1270 weak_factory_.GetWeakPtr()));
1272 } 1271 }
1273 } 1272 }
1274 1273
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( 1274 bool RenderWidgetHostViewMac::GetLineBreakIndex(
1297 const std::vector<gfx::Rect>& bounds, 1275 const std::vector<gfx::Rect>& bounds,
1298 const gfx::Range& range, 1276 const gfx::Range& range,
1299 size_t* line_break_point) { 1277 size_t* line_break_point) {
1300 DCHECK(line_break_point); 1278 DCHECK(line_break_point);
1301 if (range.start() >= bounds.size() || range.is_reversed() || range.is_empty()) 1279 if (range.start() >= bounds.size() || range.is_reversed() || range.is_empty())
1302 return false; 1280 return false;
1303 1281
1304 // We can't check line breaking completely from only rectangle array. Thus we 1282 // 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 1283 // 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
1682 render_widget_host_->SetActive(active); 1660 render_widget_host_->SetActive(active);
1683 if (active) { 1661 if (active) {
1684 if (HasFocus()) 1662 if (HasFocus())
1685 render_widget_host_->Focus(); 1663 render_widget_host_->Focus();
1686 } else { 1664 } else {
1687 render_widget_host_->Blur(); 1665 render_widget_host_->Blur();
1688 } 1666 }
1689 } 1667 }
1690 if (HasFocus()) 1668 if (HasFocus())
1691 SetTextInputActive(active); 1669 SetTextInputActive(active);
1692 if (!active) { 1670 if (!active)
1693 [cocoa_view_ setPluginImeActive:NO];
1694 UnlockMouse(); 1671 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 } 1672 }
1712 1673
1713 void RenderWidgetHostViewMac::ShowDefinitionForSelection() { 1674 void RenderWidgetHostViewMac::ShowDefinitionForSelection() {
1714 RenderWidgetHostViewMacDictionaryHelper helper(this); 1675 RenderWidgetHostViewMacDictionaryHelper helper(this);
1715 helper.ShowDefinitionForSelection(); 1676 helper.ShowDefinitionForSelection();
1716 } 1677 }
1717 1678
1718 void RenderWidgetHostViewMac::SetBackgroundColor(SkColor color) { 1679 void RenderWidgetHostViewMac::SetBackgroundColor(SkColor color) {
1719 if (color == background_color_) 1680 if (color == background_color_)
1720 return; 1681 return;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1761 if (text_input_type_ == ui::TEXT_INPUT_TYPE_PASSWORD) 1722 if (text_input_type_ == ui::TEXT_INPUT_TYPE_PASSWORD)
1762 EnablePasswordInput(); 1723 EnablePasswordInput();
1763 else 1724 else
1764 DisablePasswordInput(); 1725 DisablePasswordInput();
1765 } else { 1726 } else {
1766 if (text_input_type_ == ui::TEXT_INPUT_TYPE_PASSWORD) 1727 if (text_input_type_ == ui::TEXT_INPUT_TYPE_PASSWORD)
1767 DisablePasswordInput(); 1728 DisablePasswordInput();
1768 } 1729 }
1769 } 1730 }
1770 1731
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( 1732 void RenderWidgetHostViewMac::OnGetRenderedTextCompleted(
1781 const std::string& text) { 1733 const std::string& text) {
1782 SpeakText(text); 1734 SpeakText(text);
1783 } 1735 }
1784 1736
1785 void RenderWidgetHostViewMac::PauseForPendingResizeOrRepaintsAndDraw() { 1737 void RenderWidgetHostViewMac::PauseForPendingResizeOrRepaintsAndDraw() {
1786 if (!render_widget_host_ || render_widget_host_->is_hidden()) 1738 if (!render_widget_host_ || render_widget_host_->is_hidden())
1787 return; 1739 return;
1788 1740
1789 // Pausing for one view prevents others from receiving frames. 1741 // Pausing for one view prevents others from receiving frames.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1825 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r { 1777 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r {
1826 self = [super initWithFrame:NSZeroRect]; 1778 self = [super initWithFrame:NSZeroRect];
1827 if (self) { 1779 if (self) {
1828 self.acceptsTouchEvents = YES; 1780 self.acceptsTouchEvents = YES;
1829 editCommand_helper_.reset(new RenderWidgetHostViewMacEditCommandHelper); 1781 editCommand_helper_.reset(new RenderWidgetHostViewMacEditCommandHelper);
1830 editCommand_helper_->AddEditingSelectorsToClass([self class]); 1782 editCommand_helper_->AddEditingSelectorsToClass([self class]);
1831 1783
1832 renderWidgetHostView_.reset(r); 1784 renderWidgetHostView_.reset(r);
1833 canBeKeyView_ = YES; 1785 canBeKeyView_ = YES;
1834 opaque_ = YES; 1786 opaque_ = YES;
1835 focusedPluginIdentifier_ = -1;
1836 pinchHasReachedZoomThreshold_ = false; 1787 pinchHasReachedZoomThreshold_ = false;
1837 1788
1838 // OpenGL support: 1789 // OpenGL support:
1839 if ([self respondsToSelector: 1790 if ([self respondsToSelector:
1840 @selector(setWantsBestResolutionOpenGLSurface:)]) { 1791 @selector(setWantsBestResolutionOpenGLSurface:)]) {
1841 [self setWantsBestResolutionOpenGLSurface:YES]; 1792 [self setWantsBestResolutionOpenGLSurface:YES];
1842 } 1793 }
1843 [[NSNotificationCenter defaultCenter] 1794 [[NSNotificationCenter defaultCenter]
1844 addObserver:self 1795 addObserver:self
1845 selector:@selector(didChangeScreenParameters:) 1796 selector:@selector(didChangeScreenParameters:)
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
2201 // Clear them here so that we can know whether they have changed afterwards. 2152 // Clear them here so that we can know whether they have changed afterwards.
2202 textToBeInserted_.clear(); 2153 textToBeInserted_.clear();
2203 markedText_.clear(); 2154 markedText_.clear();
2204 markedTextSelectedRange_ = NSMakeRange(NSNotFound, 0); 2155 markedTextSelectedRange_ = NSMakeRange(NSNotFound, 0);
2205 underlines_.clear(); 2156 underlines_.clear();
2206 setMarkedTextReplacementRange_ = gfx::Range::InvalidRange(); 2157 setMarkedTextReplacementRange_ = gfx::Range::InvalidRange();
2207 unmarkTextCalled_ = NO; 2158 unmarkTextCalled_ = NO;
2208 hasEditCommands_ = NO; 2159 hasEditCommands_ = NO;
2209 editCommands_.clear(); 2160 editCommands_.clear();
2210 2161
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 2162 // Sends key down events to input method first, then we can decide what should
2218 // be done according to input method's feedback. 2163 // be done according to input method's feedback.
2219 // If a plugin is active, bypass this step since events are forwarded directly 2164 [self interpretKeyEvents:[NSArray arrayWithObject:theEvent]];
2220 // to the plugin IME.
2221 if (focusedPluginIdentifier_ == -1)
2222 [self interpretKeyEvents:[NSArray arrayWithObject:theEvent]];
2223 2165
2224 handlingKeyDown_ = NO; 2166 handlingKeyDown_ = NO;
2225 2167
2226 // Indicates if we should send the key event and corresponding editor commands 2168 // Indicates if we should send the key event and corresponding editor commands
2227 // after processing the input method result. 2169 // after processing the input method result.
2228 BOOL delayEventUntilAfterImeCompostion = NO; 2170 BOOL delayEventUntilAfterImeCompostion = NO;
2229 2171
2230 // To emulate Windows, over-write |event.windowsKeyCode| to VK_PROCESSKEY 2172 // To emulate Windows, over-write |event.windowsKeyCode| to VK_PROCESSKEY
2231 // while an input method is composing or inserting a text. 2173 // while an input method is composing or inserting a text.
2232 // Gmail checks this code in its onkeydown handler to stop auto-completing 2174 // Gmail checks this code in its onkeydown handler to stop auto-completing
(...skipping 882 matching lines...) Expand 10 before | Expand all | Expand 10 after
3115 } 3057 }
3116 3058
3117 - (NSInteger)conversationIdentifier { 3059 - (NSInteger)conversationIdentifier {
3118 return reinterpret_cast<NSInteger>(self); 3060 return reinterpret_cast<NSInteger>(self);
3119 } 3061 }
3120 3062
3121 // Each RenderWidgetHostViewCocoa has its own input context, but we return 3063 // 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 3064 // nil when the caret is in non-editable content or password box to avoid
3123 // making input methods do their work. 3065 // making input methods do their work.
3124 - (NSTextInputContext *)inputContext { 3066 - (NSTextInputContext *)inputContext {
3125 if (focusedPluginIdentifier_ != -1)
3126 return [[ComplexTextInputPanel sharedComplexTextInputPanel] inputContext];
3127
3128 switch(renderWidgetHostView_->text_input_type_) { 3067 switch(renderWidgetHostView_->text_input_type_) {
3129 case ui::TEXT_INPUT_TYPE_NONE: 3068 case ui::TEXT_INPUT_TYPE_NONE:
3130 case ui::TEXT_INPUT_TYPE_PASSWORD: 3069 case ui::TEXT_INPUT_TYPE_PASSWORD:
3131 return nil; 3070 return nil;
3132 default: 3071 default:
3133 return [super inputContext]; 3072 return [super inputContext];
3134 } 3073 }
3135 } 3074 }
3136 3075
3137 - (BOOL)hasMarkedText { 3076 - (BOOL)hasMarkedText {
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
3270 3209
3271 - (void)viewDidMoveToWindow { 3210 - (void)viewDidMoveToWindow {
3272 if ([self window]) { 3211 if ([self window]) {
3273 [self updateScreenProperties]; 3212 [self updateScreenProperties];
3274 } else { 3213 } else {
3275 // If the RenderWidgetHostViewCocoa is being removed from its window, tear 3214 // If the RenderWidgetHostViewCocoa is being removed from its window, tear
3276 // down its browser compositor resources, if needed. 3215 // down its browser compositor resources, if needed.
3277 renderWidgetHostView_->DestroySuspendedBrowserCompositorViewIfNeeded(); 3216 renderWidgetHostView_->DestroySuspendedBrowserCompositorViewIfNeeded();
3278 } 3217 }
3279 3218
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 3219 // If we switch windows (or are removed from the view hierarchy), cancel any
3297 // open mouse-downs. 3220 // open mouse-downs.
3298 if (hasOpenMouseDown_) { 3221 if (hasOpenMouseDown_) {
3299 WebMouseEvent event; 3222 WebMouseEvent event;
3300 event.type = WebInputEvent::MouseUp; 3223 event.type = WebInputEvent::MouseUp;
3301 event.button = WebMouseEvent::ButtonLeft; 3224 event.button = WebMouseEvent::ButtonLeft;
3302 renderWidgetHostView_->ForwardMouseEvent(event); 3225 renderWidgetHostView_->ForwardMouseEvent(event);
3303 3226
3304 hasOpenMouseDown_ = NO; 3227 hasOpenMouseDown_ = NO;
3305 } 3228 }
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
3397 if (!hasMarkedText_) 3320 if (!hasMarkedText_)
3398 return; 3321 return;
3399 3322
3400 if (renderWidgetHostView_->render_widget_host_) 3323 if (renderWidgetHostView_->render_widget_host_)
3401 renderWidgetHostView_->render_widget_host_->ImeConfirmComposition( 3324 renderWidgetHostView_->render_widget_host_->ImeConfirmComposition(
3402 base::string16(), gfx::Range::InvalidRange(), false); 3325 base::string16(), gfx::Range::InvalidRange(), false);
3403 3326
3404 [self cancelComposition]; 3327 [self cancelComposition];
3405 } 3328 }
3406 3329
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. 3330 // Overriding a NSResponder method to support application services.
3456 3331
3457 - (id)validRequestorForSendType:(NSString*)sendType 3332 - (id)validRequestorForSendType:(NSString*)sendType
3458 returnType:(NSString*)returnType { 3333 returnType:(NSString*)returnType {
3459 id requestor = nil; 3334 id requestor = nil;
3460 BOOL sendTypeIsString = [sendType isEqual:NSStringPboardType]; 3335 BOOL sendTypeIsString = [sendType isEqual:NSStringPboardType];
3461 BOOL returnTypeIsString = [returnType isEqual:NSStringPboardType]; 3336 BOOL returnTypeIsString = [returnType isEqual:NSStringPboardType];
3462 BOOL hasText = !renderWidgetHostView_->selected_text().empty(); 3337 BOOL hasText = !renderWidgetHostView_->selected_text().empty();
3463 BOOL takesText = 3338 BOOL takesText =
3464 renderWidgetHostView_->text_input_type_ != ui::TEXT_INPUT_TYPE_NONE; 3339 renderWidgetHostView_->text_input_type_ != ui::TEXT_INPUT_TYPE_NONE;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
3524 3399
3525 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding 3400 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding
3526 // regions that are not draggable. (See ControlRegionView in 3401 // regions that are not draggable. (See ControlRegionView in
3527 // native_app_window_cocoa.mm). This requires the render host view to be 3402 // native_app_window_cocoa.mm). This requires the render host view to be
3528 // draggable by default. 3403 // draggable by default.
3529 - (BOOL)mouseDownCanMoveWindow { 3404 - (BOOL)mouseDownCanMoveWindow {
3530 return YES; 3405 return YES;
3531 } 3406 }
3532 3407
3533 @end 3408 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698