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

Unified Diff: chrome/browser/cocoa/autocomplete_text_field.mm

Issue 295036: [Mac] Simplify field editor code which tracks whether editor rect changed. (Closed)
Patch Set: Pinks comments. Created 11 years, 2 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 | « no previous file | chrome/browser/cocoa/autocomplete_text_field_cell.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/cocoa/autocomplete_text_field.mm
diff --git a/chrome/browser/cocoa/autocomplete_text_field.mm b/chrome/browser/cocoa/autocomplete_text_field.mm
index d135854cc4016133ee4f904bddeb83eeb30f462d..91ac9989e15867f552ab4eeb4e561037d301ad86 100644
--- a/chrome/browser/cocoa/autocomplete_text_field.mm
+++ b/chrome/browser/cocoa/autocomplete_text_field.mm
@@ -38,27 +38,37 @@
// could disrupt editing. This code repositions the subview directly,
// which causes no editing-state changes.
- (void)resetFieldEditorFrameIfNeeded {
- AutocompleteTextFieldCell* cell = [self cell];
- if ([cell fieldEditorNeedsReset]) {
- // No change to bounds necessary if not editing.
- NSText* editor = [self currentEditor];
- if (editor) {
- // When editing, we should have exactly one subview, which is a
- // clipview containing the editor (for purposes of scrolling).
- NSArray* subviews = [self subviews];
- DCHECK_EQ([subviews count], 1U);
- DCHECK([editor isDescendantOf:self]);
- if ([subviews count] > 0) {
- const NSRect frame([cell drawingRectForBounds:[self bounds]]);
- [[subviews objectAtIndex:0] setFrame:frame];
-
- // Make sure the selection remains visible.
- // TODO(shess) Could this be janky?
- [editor scrollRangeToVisible:[editor selectedRange]];
- }
- }
- [cell setFieldEditorNeedsReset:NO];
+ // No action if not editing.
+ NSText* editor = [self currentEditor];
+ if (!editor) {
+ return;
+ }
+
+ // When editing, we should have exactly one subview, which is a
+ // clipview containing the editor (for purposes of scrolling).
+ NSArray* subviews = [self subviews];
+ DCHECK_EQ([subviews count], 1U);
+ DCHECK([editor isDescendantOf:self]);
+ if ([subviews count] == 0) {
+ return;
+ }
+
+ // If the frame is already right, don't make any visible changes.
+ AutocompleteTextFieldCell* cell = [self autocompleteTextFieldCell];
+ const NSRect frame([cell drawingRectForBounds:[self bounds]]);
+ NSView* subview = [subviews objectAtIndex:0];
+ if (NSEqualRects(frame, [subview frame])) {
+ return;
}
+
+ [subview setFrame:frame];
+
+ // Make sure the selection remains visible.
+ // TODO(shess) This could be janky if it jerks the visible region
+ // around too much. I believe that text fields only scroll in
+ // response to selection movement (continuing the selection past the
+ // edge, or arrowing the cursor around).
+ [editor scrollRangeToVisible:[editor selectedRange]];
}
// Reroute events for the decoration area to the field editor. This
« no previous file with comments | « no previous file | chrome/browser/cocoa/autocomplete_text_field_cell.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698