Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #import "ui/views/cocoa/bridged_content_view.h" | 5 #import "ui/views/cocoa/bridged_content_view.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #import "base/mac/scoped_nsobject.h" | 8 #import "base/mac/scoped_nsobject.h" |
| 9 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
| 10 #include "skia/ext/skia_utils_mac.h" | 10 #include "skia/ext/skia_utils_mac.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 49 bool DispatchEventToMenu(views::Widget* widget, ui::KeyboardCode key_code) { | 49 bool DispatchEventToMenu(views::Widget* widget, ui::KeyboardCode key_code) { |
| 50 MenuController* menuController = MenuController::GetActiveInstance(); | 50 MenuController* menuController = MenuController::GetActiveInstance(); |
| 51 if (menuController && menuController->owner() == widget) { | 51 if (menuController && menuController->owner() == widget) { |
| 52 if (menuController->OnWillDispatchKeyEvent(0, key_code) == | 52 if (menuController->OnWillDispatchKeyEvent(0, key_code) == |
| 53 ui::POST_DISPATCH_NONE) | 53 ui::POST_DISPATCH_NONE) |
| 54 return true; | 54 return true; |
| 55 } | 55 } |
| 56 return false; | 56 return false; |
| 57 } | 57 } |
| 58 | 58 |
| 59 gfx::Rect GetFirstRectForRangeHelper( | |
| 60 const ui::TextInputClient* textInputClient_, | |
|
tapted
2015/12/17 08:42:20
no trailing underscores on function arguments (als
karandeepb
2015/12/18 09:15:06
Done.
| |
| 61 const gfx::Range& range, | |
|
tapted
2015/12/17 08:42:20
range -> requested_range? (for clarity)
karandeepb
2015/12/18 09:15:06
Done.
| |
| 62 gfx::Range& actual_range) { | |
|
tapted
2015/12/17 08:42:20
chromium style doesn't allow non-const references,
karandeepb
2015/12/18 09:15:06
Done.
| |
| 63 if (!textInputClient_) | |
| 64 return gfx::Rect(0, 0, 0, 0); | |
|
tapted
2015/12/17 08:42:20
return gfx::Rect();
karandeepb
2015/12/18 09:15:06
Done.
| |
| 65 | |
| 66 // Set up default return values, to be returned in case of unusual cases. | |
| 67 gfx::Rect caret_bounds = textInputClient_->GetCaretBounds(); | |
| 68 caret_bounds.set_width(0); | |
| 69 actual_range.set_start(range.start()); | |
|
tapted
2015/12/17 08:42:19
*actual_range = gfx::Range(requested_rangerange.st
karandeepb
2015/12/18 09:15:06
actual_range should correspond to the returned rec
| |
| 70 actual_range.set_end(range.start()); | |
| 71 | |
| 72 if (!textInputClient_->HasCompositionText()) | |
| 73 return caret_bounds; | |
| 74 | |
| 75 if (range.is_reversed()) | |
|
tapted
2015/12/17 08:42:19
I'm pretty sure it's impossible for requested_rang
karandeepb
2015/12/18 09:15:06
Done.
| |
| 76 return caret_bounds; | |
| 77 | |
| 78 gfx::Range composition_range; | |
| 79 if (!textInputClient_->GetCompositionTextRange(&composition_range)) | |
| 80 return caret_bounds; | |
| 81 | |
| 82 if (!composition_range.Contains(gfx::Range(range.start())) || | |
|
tapted
2015/12/17 08:42:20
why not just `if (!composition_range.Contains(requ
karandeepb
2015/12/18 09:15:06
Done.
| |
| 83 !composition_range.Contains(gfx::Range(range.end()))) | |
| 84 return caret_bounds; | |
| 85 | |
| 86 // If range is empty, return a zero width rectangle corresponding to the | |
| 87 // queried range. | |
| 88 if (range.is_empty()) { | |
| 89 size_t end_index = composition_range.end(); | |
| 90 gfx::Rect current_rect; | |
| 91 if (range.start() == end_index) { | |
| 92 // Return a rectangle corresponding to the top right corner of the last | |
| 93 // compositioned character. | |
| 94 if (!textInputClient_->GetCompositionCharacterBounds( | |
| 95 end_index - 1 - composition_range.start(), ¤t_rect)) | |
|
tapted
2015/12/17 08:42:19
would RenderWidgetHostViewMac::ConvertCharacterRan
karandeepb
2015/12/18 09:15:06
Done.
| |
| 96 return caret_bounds; | |
| 97 current_rect.set_origin(current_rect.top_right()); | |
| 98 } else if (!textInputClient_->GetCompositionCharacterBounds( | |
| 99 range.start() - composition_range.start(), ¤t_rect)) | |
|
tapted
2015/12/17 08:42:20
this `else if` needs curlies, since it's attached
karandeepb
2015/12/18 09:15:06
Done.
| |
| 100 return caret_bounds; | |
| 101 current_rect.set_width(0); | |
| 102 return current_rect; | |
| 103 } | |
| 104 | |
| 105 // In browser multi-line textfields are not supported by Chrome currently. | |
|
tapted
2015/12/17 08:42:19
Perhaps something like
// Toolkit-views textfie
karandeepb
2015/12/18 09:15:06
Done.
| |
| 106 // Hence we don't check for a line break. | |
| 107 | |
| 108 // Return the union rectangle of the character bounds within the query range. | |
| 109 gfx::Rect union_rect, current_rect; | |
| 110 for (size_t i = range.start(); i < range.end(); i++) { | |
| 111 if (textInputClient_->GetCompositionCharacterBounds( | |
| 112 i - composition_range.start(), ¤t_rect)) | |
| 113 union_rect.Union(current_rect); | |
| 114 else if (i == range.start()) | |
| 115 return caret_bounds; | |
|
tapted
2015/12/17 08:42:19
can this be dealt with outside the loop? (maybe st
karandeepb
2015/12/18 09:15:06
Done.
| |
| 116 else { | |
|
tapted
2015/12/17 08:42:19
if any bit of an if/else chain has a curly, it all
karandeepb
2015/12/18 09:15:06
Done.
| |
| 117 actual_range.set_end(i); | |
| 118 return union_rect; | |
| 119 } | |
| 120 } | |
| 121 actual_range.set_end(range.end()); | |
| 122 return union_rect; | |
| 123 } | |
| 124 | |
| 59 } // namespace | 125 } // namespace |
| 60 | 126 |
| 61 @interface BridgedContentView () | 127 @interface BridgedContentView () |
| 62 | 128 |
| 63 // Translates keycodes and modifiers on |theEvent| to ui::KeyEvents and passes | 129 // Translates keycodes and modifiers on |theEvent| to ui::KeyEvents and passes |
| 64 // the event to the InputMethod for dispatch. | 130 // the event to the InputMethod for dispatch. |
| 65 - (void)handleKeyEvent:(NSEvent*)theEvent; | 131 - (void)handleKeyEvent:(NSEvent*)theEvent; |
| 66 | 132 |
| 67 // Handles an NSResponder Action Message by mapping it to a corresponding text | 133 // Handles an NSResponder Action Message by mapping it to a corresponding text |
| 68 // editing command from ui_strings.grd and, when not being sent to a | 134 // editing command from ui_strings.grd and, when not being sent to a |
| (...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 585 } | 651 } |
| 586 | 652 |
| 587 if ([self respondsToSelector:selector]) | 653 if ([self respondsToSelector:selector]) |
| 588 [self performSelector:selector withObject:nil]; | 654 [self performSelector:selector withObject:nil]; |
| 589 else | 655 else |
| 590 [[self nextResponder] doCommandBySelector:selector]; | 656 [[self nextResponder] doCommandBySelector:selector]; |
| 591 } | 657 } |
| 592 | 658 |
| 593 - (NSRect)firstRectForCharacterRange:(NSRange)range | 659 - (NSRect)firstRectForCharacterRange:(NSRange)range |
| 594 actualRange:(NSRangePointer)actualRange { | 660 actualRange:(NSRangePointer)actualRange { |
| 595 NOTIMPLEMENTED(); | 661 gfx::Range requested_range(range); |
|
tapted
2015/12/17 08:42:20
since this is between @implementation and @end (i.
karandeepb
2015/12/18 09:15:06
Done.
| |
| 596 return NSZeroRect; | 662 gfx::Range actual_range; |
| 663 gfx::Rect rect = GetFirstRectForRangeHelper(textInputClient_, requested_range, | |
| 664 actual_range); | |
| 665 NSRect ns_rect = NSRectFromCGRect(rect.ToCGRect()); | |
| 666 if (NSEqualRects(ns_rect, NSZeroRect)) { | |
|
tapted
2015/12/17 08:42:19
nit: move this up a line and do
if (rect.IsEmpty(
karandeepb
2015/12/18 09:15:06
Removed the early exit. Also, its unlikely for tex
| |
| 667 return NSZeroRect; | |
| 668 } | |
| 669 *actualRange = actual_range.ToNSRange(); | |
| 670 // ns_rect is in screen coordinates with origin at top left. Convert to Apple | |
|
tapted
2015/12/17 08:42:20
return gfx::ScreenRectToNSRect(screen_rect);
karandeepb
2015/12/18 09:15:06
Done.
| |
| 671 // coordinate system with origin at bottom left | |
| 672 NSRect screen_rect = [[NSScreen mainScreen] frame]; | |
| 673 ns_rect.origin.y = screen_rect.size.height - NSMaxY(ns_rect); | |
| 674 return ns_rect; | |
| 597 } | 675 } |
| 598 | 676 |
| 599 - (BOOL)hasMarkedText { | 677 - (BOOL)hasMarkedText { |
| 600 return textInputClient_ && textInputClient_->HasCompositionText(); | 678 return textInputClient_ && textInputClient_->HasCompositionText(); |
| 601 } | 679 } |
| 602 | 680 |
| 603 - (void)insertText:(id)text replacementRange:(NSRange)replacementRange { | 681 - (void)insertText:(id)text replacementRange:(NSRange)replacementRange { |
| 604 if (!hostedView_) | 682 if (!hostedView_) |
| 605 return; | 683 return; |
| 606 | 684 |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 722 } | 800 } |
| 723 | 801 |
| 724 return [super accessibilityAttributeValue:attribute]; | 802 return [super accessibilityAttributeValue:attribute]; |
| 725 } | 803 } |
| 726 | 804 |
| 727 - (id)accessibilityHitTest:(NSPoint)point { | 805 - (id)accessibilityHitTest:(NSPoint)point { |
| 728 return [hostedView_->GetNativeViewAccessible() accessibilityHitTest:point]; | 806 return [hostedView_->GetNativeViewAccessible() accessibilityHitTest:point]; |
| 729 } | 807 } |
| 730 | 808 |
| 731 @end | 809 @end |
| OLD | NEW |