Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <QuartzCore/QuartzCore.h> | 5 #include <QuartzCore/QuartzCore.h> |
| 6 | 6 |
| 7 #include "chrome/browser/renderer_host/render_widget_host_view_mac.h" | 7 #include "chrome/browser/renderer_host/render_widget_host_view_mac.h" |
| 8 | 8 |
| 9 #include "app/app_switches.h" | 9 #include "app/app_switches.h" |
| 10 #include "app/surface/io_surface_support_mac.h" | 10 #include "app/surface/io_surface_support_mac.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/mac/scoped_cftyperef.h" | 13 #include "base/mac/scoped_cftyperef.h" |
| 14 #import "base/mac/scoped_nsautorelease_pool.h" | 14 #import "base/mac/scoped_nsautorelease_pool.h" |
| 15 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
| 16 #import "base/scoped_nsobject.h" | 16 #import "base/scoped_nsobject.h" |
| 17 #include "base/string_util.h" | 17 #include "base/string_util.h" |
| 18 #include "base/sys_info.h" | 18 #include "base/sys_info.h" |
| 19 #include "base/sys_string_conversions.h" | 19 #include "base/sys_string_conversions.h" |
| 20 #import "chrome/browser/accessibility/browser_accessibility_cocoa.h" | 20 #import "chrome/browser/accessibility/browser_accessibility_cocoa.h" |
| 21 #include "chrome/browser/accessibility/browser_accessibility_state.h" | 21 #include "chrome/browser/accessibility/browser_accessibility_state.h" |
| 22 #include "chrome/browser/browser_thread.h" | 22 #include "chrome/browser/browser_thread.h" |
| 23 #include "chrome/browser/browser_trial.h" | 23 #include "chrome/browser/browser_trial.h" |
| 24 #include "chrome/browser/gpu_process_host.h" | 24 #include "chrome/browser/gpu_process_host.h" |
| 25 #include "chrome/browser/plugin_process_host.h" | 25 #include "chrome/browser/plugin_process_host.h" |
| 26 #include "chrome/browser/renderer_host/backing_store_mac.h" | 26 #include "chrome/browser/renderer_host/backing_store_mac.h" |
| 27 #include "chrome/browser/renderer_host/render_process_host.h" | 27 #include "chrome/browser/renderer_host/render_process_host.h" |
| 28 #include "chrome/browser/renderer_host/render_view_host.h" | 28 #include "chrome/browser/renderer_host/render_view_host.h" |
| 29 #include "chrome/browser/renderer_host/render_widget_host.h" | 29 #include "chrome/browser/renderer_host/render_widget_host.h" |
| 30 #include "chrome/browser/spellchecker_platform_engine.h" | 30 #include "chrome/browser/spellchecker_platform_engine.h" |
| 31 #import "chrome/browser/ui/cocoa/lookup_in_dictionary.h" | |
| 31 #import "chrome/browser/ui/cocoa/rwhvm_editcommand_helper.h" | 32 #import "chrome/browser/ui/cocoa/rwhvm_editcommand_helper.h" |
| 32 #import "chrome/browser/ui/cocoa/view_id_util.h" | 33 #import "chrome/browser/ui/cocoa/view_id_util.h" |
| 33 #include "chrome/common/chrome_switches.h" | 34 #include "chrome/common/chrome_switches.h" |
| 34 #include "chrome/common/native_web_keyboard_event.h" | 35 #include "chrome/common/native_web_keyboard_event.h" |
| 35 #include "chrome/common/edit_command.h" | 36 #include "chrome/common/edit_command.h" |
| 36 #include "chrome/common/gpu_messages.h" | 37 #include "chrome/common/gpu_messages.h" |
| 37 #include "chrome/common/plugin_messages.h" | 38 #include "chrome/common/plugin_messages.h" |
| 38 #include "chrome/common/render_messages.h" | 39 #include "chrome/common/render_messages.h" |
| 40 #include "gfx/point.h" | |
| 39 #include "skia/ext/platform_canvas.h" | 41 #include "skia/ext/platform_canvas.h" |
| 40 #include "third_party/skia/include/core/SkColor.h" | 42 #include "third_party/skia/include/core/SkColor.h" |
| 41 #include "third_party/WebKit/Source/WebKit/chromium/public/mac/WebInputEventFact ory.h" | 43 #include "third_party/WebKit/Source/WebKit/chromium/public/mac/WebInputEventFact ory.h" |
| 42 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 44 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
| 43 #include "webkit/glue/webaccessibility.h" | 45 #include "webkit/glue/webaccessibility.h" |
| 44 #include "webkit/plugins/npapi/webplugin.h" | 46 #include "webkit/plugins/npapi/webplugin.h" |
| 45 #import "third_party/mozilla/ComplexTextInputPanel.h" | 47 #import "third_party/mozilla/ComplexTextInputPanel.h" |
| 46 | 48 |
| 47 using WebKit::WebInputEvent; | 49 using WebKit::WebInputEvent; |
| 48 using WebKit::WebInputEventFactory; | 50 using WebKit::WebInputEventFactory; |
| (...skipping 672 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 721 } | 723 } |
| 722 | 724 |
| 723 void RenderWidgetHostViewMac::ImeUpdateTextInputState( | 725 void RenderWidgetHostViewMac::ImeUpdateTextInputState( |
| 724 WebKit::WebTextInputType type, | 726 WebKit::WebTextInputType type, |
| 725 const gfx::Rect& caret_rect) { | 727 const gfx::Rect& caret_rect) { |
| 726 if (text_input_type_ != type) { | 728 if (text_input_type_ != type) { |
| 727 text_input_type_ = type; | 729 text_input_type_ = type; |
| 728 if (HasFocus()) | 730 if (HasFocus()) |
| 729 SetTextInputActive(true); | 731 SetTextInputActive(true); |
| 730 } | 732 } |
| 731 | |
| 732 // We need to convert the coordinate of the cursor rectangle sent from the | |
| 733 // renderer and save it. Our input method backend uses a coordinate system | |
| 734 // whose origin is the upper-left corner of this view. On the other hand, | |
| 735 // Cocoa uses a coordinate system whose origin is the lower-left corner of | |
| 736 // this view. So, we convert the cursor rectangle and save it. | |
| 737 [cocoa_view_ setCaretRect:[cocoa_view_ flipRectToNSRect:caret_rect]]; | |
| 738 } | 733 } |
| 739 | 734 |
| 740 void RenderWidgetHostViewMac::ImeCancelComposition() { | 735 void RenderWidgetHostViewMac::ImeCancelComposition() { |
| 741 [cocoa_view_ cancelComposition]; | 736 [cocoa_view_ cancelComposition]; |
| 742 } | 737 } |
| 743 | 738 |
| 744 void RenderWidgetHostViewMac::DidUpdateBackingStore( | 739 void RenderWidgetHostViewMac::DidUpdateBackingStore( |
| 745 const gfx::Rect& scroll_rect, int scroll_dx, int scroll_dy, | 740 const gfx::Rect& scroll_rect, int scroll_dx, int scroll_dy, |
| 746 const std::vector<gfx::Rect>& copy_rects) { | 741 const std::vector<gfx::Rect>& copy_rects) { |
| 747 if (!is_hidden_) { | 742 if (!is_hidden_) { |
| (...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1312 } else { | 1307 } else { |
| 1313 if (text_input_type_ == WebKit::WebTextInputTypePassword) | 1308 if (text_input_type_ == WebKit::WebTextInputTypePassword) |
| 1314 DisablePasswordInput(); | 1309 DisablePasswordInput(); |
| 1315 } | 1310 } |
| 1316 } | 1311 } |
| 1317 | 1312 |
| 1318 // RenderWidgetHostViewCocoa --------------------------------------------------- | 1313 // RenderWidgetHostViewCocoa --------------------------------------------------- |
| 1319 | 1314 |
| 1320 @implementation RenderWidgetHostViewCocoa | 1315 @implementation RenderWidgetHostViewCocoa |
| 1321 | 1316 |
| 1322 @synthesize caretRect = caretRect_; | |
| 1323 | |
| 1324 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r { | 1317 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r { |
| 1325 self = [super initWithFrame:NSZeroRect]; | 1318 self = [super initWithFrame:NSZeroRect]; |
| 1326 if (self) { | 1319 if (self) { |
| 1327 editCommand_helper_.reset(new RWHVMEditCommandHelper); | 1320 editCommand_helper_.reset(new RWHVMEditCommandHelper); |
| 1328 editCommand_helper_->AddEditingSelectorsToClass([self class]); | 1321 editCommand_helper_->AddEditingSelectorsToClass([self class]); |
| 1329 | 1322 |
| 1330 renderWidgetHostView_.reset(r); | 1323 renderWidgetHostView_.reset(r); |
| 1331 canBeKeyView_ = YES; | 1324 canBeKeyView_ = YES; |
| 1332 takesFocusOnlyOnMouseDown_ = NO; | 1325 takesFocusOnlyOnMouseDown_ = NO; |
| 1333 closeOnDeactivate_ = NO; | 1326 closeOnDeactivate_ = NO; |
| (...skipping 1005 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2339 NSUnderlineStyleAttributeName, | 2332 NSUnderlineStyleAttributeName, |
| 2340 NSUnderlineColorAttributeName, | 2333 NSUnderlineColorAttributeName, |
| 2341 NSMarkedClauseSegmentAttributeName, | 2334 NSMarkedClauseSegmentAttributeName, |
| 2342 NSTextInputReplacementRangeAttributeName, | 2335 NSTextInputReplacementRangeAttributeName, |
| 2343 nil]); | 2336 nil]); |
| 2344 } | 2337 } |
| 2345 return validAttributesForMarkedText_.get(); | 2338 return validAttributesForMarkedText_.get(); |
| 2346 } | 2339 } |
| 2347 | 2340 |
| 2348 - (NSUInteger)characterIndexForPoint:(NSPoint)thePoint { | 2341 - (NSUInteger)characterIndexForPoint:(NSPoint)thePoint { |
| 2349 NOTIMPLEMENTED(); | 2342 DCHECK([self window]); |
| 2350 return NSNotFound; | 2343 // |thePoint| is in screen coordinates, but needs to be converted to WebKit |
| 2344 // coordinates (upper left origin). Scroll offsets will be taken care of in | |
| 2345 // the renderer. | |
| 2346 thePoint = [[self window] convertScreenToBase:thePoint]; | |
| 2347 thePoint = [self convertPoint:thePoint fromView:nil]; | |
| 2348 thePoint.y = NSHeight([self frame]) - thePoint.y; | |
| 2349 | |
| 2350 LookupInDictionary* service = LookupInDictionary::GetInstance(); | |
| 2351 service->BeforeRequest(); | |
| 2352 renderWidgetHostView_->render_widget_host_->Send( | |
| 2353 new ViewMsg_CharacterIndexForPoint( | |
| 2354 renderWidgetHostView_->render_widget_host_->routing_id(), | |
| 2355 gfx::Point(thePoint.x, thePoint.y))); | |
| 2356 NSUInteger index = service->WaitForCharacterIndex(); | |
| 2357 service->AfterRequest(); | |
|
James Su
2011/01/19 20:29:06
I'm wondering if it's possible to move this piece
Robert Sesek
2011/01/20 15:06:33
I was wondering the same thing. I could add a IPC:
James Su
2011/01/20 23:46:05
I mean is it possible to simplify this part to som
Robert Sesek
2011/01/21 23:40:07
Done.
| |
| 2358 return index; | |
| 2351 } | 2359 } |
| 2352 | 2360 |
| 2353 - (NSRect)firstRectForCharacterRange:(NSRange)theRange { | 2361 - (NSRect)firstRectForCharacterRange:(NSRange)theRange { |
| 2354 // An input method requests a cursor rectangle to display its candidate | 2362 LookupInDictionary* service = LookupInDictionary::GetInstance(); |
| 2355 // window. | 2363 service->BeforeRequest(); |
| 2356 // Calculate the screen coordinate of the cursor rectangle saved in | 2364 renderWidgetHostView_->render_widget_host_->Send( |
| 2357 // RenderWidgetHostViewMac::ImeUpdateTextInputState() and send it to the | 2365 new ViewMsg_FirstRectForCharacterRange( |
| 2358 // input method. | 2366 renderWidgetHostView_->render_widget_host_->routing_id(), |
| 2359 // Since this window may be moved since we receive the cursor rectangle last | 2367 theRange.location, |
| 2360 // time we sent the cursor rectangle to the input method, so we should map | 2368 theRange.length)); |
| 2361 // from the view coordinate to the screen coordinate every time when an input | 2369 NSRect rect = service->WaitForFirstRect(); |
| 2362 // method need it. | 2370 service->AfterRequest(); |
| 2363 NSRect resultRect = [self convertRect:caretRect_ toView:nil]; | 2371 // The returned rectangle is in WebKit coordinates (upper left origin), so |
| 2364 NSWindow* window = [self window]; | 2372 // flip the coordinate system and then convert it into screen coordinates for |
| 2365 if (window) | 2373 // return. |
| 2366 resultRect.origin = [window convertBaseToScreen:resultRect.origin]; | 2374 NSRect viewFrame = [self frame]; |
| 2367 | 2375 rect.origin.y = NSHeight(viewFrame) - rect.origin.y; |
| 2368 return resultRect; | 2376 rect.origin.y -= rect.size.height; |
| 2377 rect = [self convertRectToBase:rect]; | |
| 2378 rect.origin = [[self window] convertBaseToScreen:rect.origin]; | |
| 2379 return rect; | |
| 2369 } | 2380 } |
| 2370 | 2381 |
| 2371 - (NSRange)selectedRange { | 2382 - (NSRange)selectedRange { |
| 2372 // Return the selected range saved in the setMarkedText method. | 2383 // Return the selected range saved in the setMarkedText method. |
| 2373 return hasMarkedText_ ? selectedRange_ : NSMakeRange(NSNotFound, 0); | 2384 return hasMarkedText_ ? selectedRange_ : NSMakeRange(NSNotFound, 0); |
| 2374 } | 2385 } |
| 2375 | 2386 |
| 2376 - (NSRange)markedRange { | 2387 - (NSRange)markedRange { |
| 2377 // An input method calls this method to check if an application really has | 2388 // An input method calls this method to check if an application really has |
| 2378 // a text being composed when hasMarkedText call returns true. | 2389 // a text being composed when hasMarkedText call returns true. |
| 2379 // Returns the range saved in the setMarkedText method so the input method | 2390 // Returns the range saved in the setMarkedText method so the input method |
| 2380 // calls the setMarkedText method and we can update the composition node | 2391 // calls the setMarkedText method and we can update the composition node |
| 2381 // there. (When this method returns an empty range, the input method doesn't | 2392 // there. (When this method returns an empty range, the input method doesn't |
| 2382 // call the setMarkedText method.) | 2393 // call the setMarkedText method.) |
| 2383 return hasMarkedText_ ? markedRange_ : NSMakeRange(NSNotFound, 0); | 2394 return hasMarkedText_ ? markedRange_ : NSMakeRange(NSNotFound, 0); |
| 2384 } | 2395 } |
| 2385 | 2396 |
| 2386 - (NSAttributedString *)attributedSubstringFromRange:(NSRange)range { | 2397 - (NSAttributedString*)attributedSubstringFromRange:(NSRange)range { |
| 2387 // TODO(hbono): Even though many input method works without implementing | 2398 LookupInDictionary* service = LookupInDictionary::GetInstance(); |
| 2388 // this method, we need to save a copy of the string in the setMarkedText | 2399 service->BeforeRequest(); |
| 2389 // method and create a NSAttributedString with the given range. | 2400 renderWidgetHostView_->render_widget_host_->Send( |
| 2390 // http://crbug.com/37715 | 2401 new ViewMsg_StringForRange( |
| 2391 return nil; | 2402 renderWidgetHostView_->render_widget_host_->routing_id(), |
| 2403 range.location, | |
| 2404 range.length)); | |
| 2405 NSAttributedString* string = service->WaitForSubstring(); | |
| 2406 service->AfterRequest(); | |
| 2407 return string; | |
| 2392 } | 2408 } |
| 2393 | 2409 |
| 2394 - (NSInteger)conversationIdentifier { | 2410 - (NSInteger)conversationIdentifier { |
| 2395 return reinterpret_cast<NSInteger>(self); | 2411 return reinterpret_cast<NSInteger>(self); |
| 2396 } | 2412 } |
| 2397 | 2413 |
| 2398 // Each RenderWidgetHostViewCocoa has its own input context, but we return | 2414 // Each RenderWidgetHostViewCocoa has its own input context, but we return |
| 2399 // nil when the caret is in non-editable content or password box to avoid | 2415 // nil when the caret is in non-editable content or password box to avoid |
| 2400 // making input methods do their work. | 2416 // making input methods do their work. |
| 2401 - (NSTextInputContext *)inputContext { | 2417 - (NSTextInputContext *)inputContext { |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2725 if (!string) return NO; | 2741 if (!string) return NO; |
| 2726 | 2742 |
| 2727 // If the user is currently using an IME, confirm the IME input, | 2743 // If the user is currently using an IME, confirm the IME input, |
| 2728 // and then insert the text from the service, the same as TextEdit and Safari. | 2744 // and then insert the text from the service, the same as TextEdit and Safari. |
| 2729 [self confirmComposition]; | 2745 [self confirmComposition]; |
| 2730 [self insertText:string]; | 2746 [self insertText:string]; |
| 2731 return YES; | 2747 return YES; |
| 2732 } | 2748 } |
| 2733 | 2749 |
| 2734 @end | 2750 @end |
| OLD | NEW |