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

Unified Diff: ui/views/cocoa/bridged_content_view.mm

Issue 2955073002: Manky attempt with TextInputClient
Patch Set: Created 3 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/accessibility/native_view_accessibility_base.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/cocoa/bridged_content_view.mm
diff --git a/ui/views/cocoa/bridged_content_view.mm b/ui/views/cocoa/bridged_content_view.mm
index 46e34d86737b6a9716db18835ad7ea1b38f59c4d..3d763f048d9d2b88d82a3cee70e02b2f808e9104 100644
--- a/ui/views/cocoa/bridged_content_view.mm
+++ b/ui/views/cocoa/bridged_content_view.mm
@@ -17,6 +17,7 @@
#include "ui/base/ime/input_method.h"
#include "ui/base/ime/text_edit_commands.h"
#include "ui/base/ime/text_input_client.h"
+#include "ui/base/text/text_properties.h"
#include "ui/compositor/canvas_painter.h"
#import "ui/events/cocoa/cocoa_event_utils.h"
#include "ui/events/event_utils.h"
@@ -84,88 +85,6 @@ bool DispatchEventToMenu(MenuController* menu_controller, ui::KeyEvent* event) {
ui::POST_DISPATCH_NONE;
}
-// Returns true if |client| has RTL text.
-bool IsTextRTL(const ui::TextInputClient* client) {
- return client && client->GetTextDirection() == base::i18n::RIGHT_TO_LEFT;
-}
-
-// Returns the boundary rectangle for composition characters in the
-// |requested_range|. Sets |actual_range| corresponding to the returned
-// rectangle. For cases, where there is no composition text or the
-// |requested_range| lies outside the composition range, a zero width rectangle
-// corresponding to the caret bounds is returned. Logic used is similar to
-// RenderWidgetHostViewMac::GetCachedFirstRectForCharacterRange(...).
-gfx::Rect GetFirstRectForRangeHelper(const ui::TextInputClient* client,
- const gfx::Range& requested_range,
- gfx::Range* actual_range) {
- // NSRange doesn't support reversed ranges.
- DCHECK(!requested_range.is_reversed());
- DCHECK(actual_range);
-
- // Set up default return values, to be returned in case of unusual cases.
- gfx::Rect default_rect;
- *actual_range = gfx::Range::InvalidRange();
- if (!client)
- return default_rect;
-
- default_rect = client->GetCaretBounds();
- default_rect.set_width(0);
-
- // If possible, modify actual_range to correspond to caret position.
- gfx::Range selection_range;
- if (client->GetSelectionRange(&selection_range)) {
- // Caret bounds correspond to end index of selection_range.
- *actual_range = gfx::Range(selection_range.end());
- }
-
- gfx::Range composition_range;
- if (!client->HasCompositionText() ||
- !client->GetCompositionTextRange(&composition_range) ||
- !composition_range.Contains(requested_range))
- return default_rect;
-
- DCHECK(!composition_range.is_reversed());
-
- const size_t from = requested_range.start() - composition_range.start();
- const size_t to = requested_range.end() - composition_range.start();
-
- // Pick the first character's bounds as the initial rectangle, then grow it to
- // the full |requested_range| if possible.
- const bool request_is_composition_end = from == composition_range.length();
- const size_t first_index = request_is_composition_end ? from - 1 : from;
- gfx::Rect union_rect;
- if (!client->GetCompositionCharacterBounds(first_index, &union_rect))
- return default_rect;
-
- // If requested_range is empty, return a zero width rectangle corresponding to
- // it.
- if (from == to) {
- if (request_is_composition_end && !IsTextRTL(client)) {
- // In case of an empty requested range at end of composition, return the
- // rectangle to the right of the last compositioned character.
- union_rect.set_origin(union_rect.top_right());
- }
- union_rect.set_width(0);
- *actual_range = requested_range;
- return union_rect;
- }
-
- // Toolkit-views textfields are always single-line, so no need to check for
- // line breaks.
- for (size_t i = from + 1; i < to; i++) {
- gfx::Rect current_rect;
- if (client->GetCompositionCharacterBounds(i, &current_rect)) {
- union_rect.Union(current_rect);
- } else {
- *actual_range =
- gfx::Range(requested_range.start(), i + composition_range.start());
- return union_rect;
- }
- }
- *actual_range = requested_range;
- return union_rect;
-}
-
// Returns the string corresponding to |requested_range| for the given |client|.
// If a gfx::Range::InvalidRange() is passed, the full string stored by |client|
// is returned. Sets |actual_range| corresponding to the returned string.
@@ -1194,23 +1113,23 @@ ui::TextEditCommand GetTextEditCommandForMenuAction(SEL action) {
}
- (void)moveToLeftEndOfLine:(id)sender {
- IsTextRTL(textInputClient_) ? [self moveToEndOfLine:sender]
- : [self moveToBeginningOfLine:sender];
+ ui::IsTextRTL(textInputClient_) ? [self moveToEndOfLine:sender]
+ : [self moveToBeginningOfLine:sender];
}
- (void)moveToRightEndOfLine:(id)sender {
- IsTextRTL(textInputClient_) ? [self moveToBeginningOfLine:sender]
- : [self moveToEndOfLine:sender];
+ ui::IsTextRTL(textInputClient_) ? [self moveToBeginningOfLine:sender]
+ : [self moveToEndOfLine:sender];
}
- (void)moveToLeftEndOfLineAndModifySelection:(id)sender {
- IsTextRTL(textInputClient_)
+ ui::IsTextRTL(textInputClient_)
? [self moveToEndOfLineAndModifySelection:sender]
: [self moveToBeginningOfLineAndModifySelection:sender];
}
- (void)moveToRightEndOfLineAndModifySelection:(id)sender {
- IsTextRTL(textInputClient_)
+ ui::IsTextRTL(textInputClient_)
? [self moveToBeginningOfLineAndModifySelection:sender]
: [self moveToEndOfLineAndModifySelection:sender];
}
@@ -1385,8 +1304,8 @@ ui::TextEditCommand GetTextEditCommandForMenuAction(SEL action) {
- (NSRect)firstRectForCharacterRange:(NSRange)range
actualRange:(NSRangePointer)actualNSRange {
gfx::Range actualRange;
- gfx::Rect rect = GetFirstRectForRangeHelper(textInputClient_,
- gfx::Range(range), &actualRange);
+ gfx::Rect rect = ui::GetFirstRectForTextInputRange(
+ textInputClient_, gfx::Range(range), &actualRange);
if (actualNSRange)
*actualNSRange = actualRange.ToNSRange();
return gfx::ScreenRectToNSRect(rect);
« no previous file with comments | « ui/views/accessibility/native_view_accessibility_base.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698