Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.h" | 5 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/mac/foundation_util.h" | 8 #include "base/mac/foundation_util.h" |
| 9 #include "base/mac/mac_logging.h" | 9 #include "base/mac/mac_logging.h" |
| 10 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h" | 10 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h" |
| 11 #import "chrome/browser/ui/cocoa/location_bar/button_decoration.h" | 11 #import "chrome/browser/ui/cocoa/location_bar/button_decoration.h" |
| 12 #import "chrome/browser/ui/cocoa/location_bar/location_bar_decoration.h" | 12 #import "chrome/browser/ui/cocoa/location_bar/location_bar_decoration.h" |
| 13 #import "chrome/browser/ui/cocoa/nsview_additions.h" | 13 #import "chrome/browser/ui/cocoa/nsview_additions.h" |
| 14 #import "chrome/browser/ui/cocoa/tracking_area.h" | 14 #import "chrome/browser/ui/cocoa/tracking_area.h" |
| 15 #import "chrome/common/extensions/feature_switch.h" | 15 #import "chrome/common/extensions/feature_switch.h" |
| 16 #import "third_party/mozilla/NSPasteboard+Utils.h" | 16 #import "third_party/mozilla/NSPasteboard+Utils.h" |
| 17 | 17 |
| 18 using extensions::FeatureSwitch; | 18 using extensions::FeatureSwitch; |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 const CGFloat kBaselineAdjust = 3.0; | 22 const CGFloat kBaselineAdjust = 3.0; |
| 23 | 23 |
| 24 // Matches the clipping radius of |GradientButtonCell|. | 24 // Matches the clipping radius of |GradientButtonCell|. |
| 25 const CGFloat kCornerRadius = 3.0; | 25 const CGFloat kCornerRadius = 3.0; |
| 26 | 26 |
| 27 // How far to inset the left-hand decorations from the field's bounds. | 27 // How far to inset the left-hand decorations from the field's bounds. |
| 28 const CGFloat kLeftDecorationXOffset = 5.0; | 28 const CGFloat kLeftDecorationXOffset = 5.0; |
| 29 | 29 |
| 30 // Padding between the control's text and the collapsible decoration. | |
| 31 const CGFloat kAutoCollapsePadding = 20.0; | |
| 32 | |
| 30 NSString* const kButtonDecorationKey = @"ButtonDecoration"; | 33 NSString* const kButtonDecorationKey = @"ButtonDecoration"; |
| 31 | 34 |
| 32 // How far to inset the right-hand decorations from the field's bounds. | 35 // How far to inset the right-hand decorations from the field's bounds. |
| 33 // TODO(shess): Why is this different from |kLeftDecorationXOffset|? | 36 // TODO(shess): Why is this different from |kLeftDecorationXOffset|? |
| 34 // |kDecorationOuterXOffset|? | 37 // |kDecorationOuterXOffset|? |
| 35 CGFloat RightDecorationXOffset() { | 38 CGFloat RightDecorationXOffset() { |
| 36 const CGFloat kRightDecorationXOffset = 5.0; | 39 const CGFloat kRightDecorationXOffset = 5.0; |
| 37 const CGFloat kScriptBadgeRightDecorationXOffset = 9.0; | 40 const CGFloat kScriptBadgeRightDecorationXOffset = 9.0; |
| 38 | 41 |
| 39 if (FeatureSwitch::script_badges()->IsEnabled()) { | 42 if (FeatureSwitch::script_badges()->IsEnabled()) { |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 64 // visible and which fit, in the same order as |all_decorations|, | 67 // visible and which fit, in the same order as |all_decorations|, |
| 65 // while |decoration_frames| will be the corresponding frames. | 68 // while |decoration_frames| will be the corresponding frames. |
| 66 // |x_edge| describes the edge to layout the decorations against | 69 // |x_edge| describes the edge to layout the decorations against |
| 67 // (|NSMinXEdge| or |NSMaxXEdge|). |regular_padding| is the padding | 70 // (|NSMinXEdge| or |NSMaxXEdge|). |regular_padding| is the padding |
| 68 // from the edge of |cell_frame| to use when the first visible decoration | 71 // from the edge of |cell_frame| to use when the first visible decoration |
| 69 // is a regular decoration. |action_padding| is the padding to use when the | 72 // is a regular decoration. |action_padding| is the padding to use when the |
| 70 // first decoration is a button decoration, ie. the action box button. | 73 // first decoration is a button decoration, ie. the action box button. |
| 71 // (|DecorationHorizontalPad()| is used between decorations). | 74 // (|DecorationHorizontalPad()| is used between decorations). |
| 72 void CalculatePositionsHelper( | 75 void CalculatePositionsHelper( |
| 73 NSRect frame, | 76 NSRect frame, |
| 77 CGFloat text_width, | |
| 74 const std::vector<LocationBarDecoration*>& all_decorations, | 78 const std::vector<LocationBarDecoration*>& all_decorations, |
| 75 NSRectEdge x_edge, | 79 NSRectEdge x_edge, |
| 76 CGFloat regular_padding, | 80 CGFloat regular_padding, |
| 77 CGFloat action_padding, | 81 CGFloat action_padding, |
| 78 std::vector<LocationBarDecoration*>* decorations, | 82 std::vector<LocationBarDecoration*>* decorations, |
| 79 std::vector<NSRect>* decoration_frames, | 83 std::vector<NSRect>* decoration_frames, |
| 80 NSRect* remaining_frame) { | 84 NSRect* remaining_frame) { |
| 81 DCHECK(x_edge == NSMinXEdge || x_edge == NSMaxXEdge); | 85 DCHECK(x_edge == NSMinXEdge || x_edge == NSMaxXEdge); |
| 82 DCHECK_EQ(decorations->size(), decoration_frames->size()); | 86 DCHECK_EQ(decorations->size(), decoration_frames->size()); |
| 83 | 87 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 94 is_first_visible_decoration = false; | 98 is_first_visible_decoration = false; |
| 95 } | 99 } |
| 96 | 100 |
| 97 NSRect padding_rect, available; | 101 NSRect padding_rect, available; |
| 98 | 102 |
| 99 // Peel off the outside padding. | 103 // Peel off the outside padding. |
| 100 NSDivideRect(frame, &padding_rect, &available, padding, x_edge); | 104 NSDivideRect(frame, &padding_rect, &available, padding, x_edge); |
| 101 | 105 |
| 102 // Find out how large the decoration will be in the remaining | 106 // Find out how large the decoration will be in the remaining |
| 103 // space. | 107 // space. |
| 104 const CGFloat used_width = | 108 CGFloat used_width = |
| 105 all_decorations[i]->GetWidthForSpace(NSWidth(available)); | 109 all_decorations[i]->GetWidthForSpace(NSWidth(available)); |
| 106 | 110 |
| 111 // Collapse if necessary. | |
|
Scott Hess - ex-Googler
2013/01/28 21:37:27
Way Back When, I thought that this kind of auto-ad
sail
2013/01/29 22:31:08
I think moving this might be a good idea. In views
| |
| 112 CGFloat new_width = NSWidth(available) - used_width - | |
| 113 kAutoCollapsePadding; | |
| 114 if (all_decorations[i]->ShouldAutoCollapse() && new_width < text_width) | |
| 115 used_width = LocationBarDecoration::kOmittedWidth; | |
|
Scott Hess - ex-Googler
2013/01/28 21:37:27
I wonder if this wouldn't make more sense to fold
sail
2013/01/29 22:31:08
Done.
Moved the collapse logic to SearchTokenDecor
| |
| 116 | |
| 107 if (used_width != LocationBarDecoration::kOmittedWidth) { | 117 if (used_width != LocationBarDecoration::kOmittedWidth) { |
| 108 DCHECK_GT(used_width, 0.0); | 118 DCHECK_GT(used_width, 0.0); |
| 109 NSRect decoration_frame; | 119 NSRect decoration_frame; |
| 110 | 120 |
| 111 // Peel off the desired width, leaving the remainder in | 121 // Peel off the desired width, leaving the remainder in |
| 112 // |frame|. | 122 // |frame|. |
| 113 NSDivideRect(available, &decoration_frame, &frame, | 123 NSDivideRect(available, &decoration_frame, &frame, |
| 114 used_width, x_edge); | 124 used_width, x_edge); |
| 115 | 125 |
| 116 decorations->push_back(all_decorations[i]); | 126 decorations->push_back(all_decorations[i]); |
| 117 decoration_frames->push_back(decoration_frame); | 127 decoration_frames->push_back(decoration_frame); |
| 118 DCHECK_EQ(decorations->size(), decoration_frames->size()); | 128 DCHECK_EQ(decorations->size(), decoration_frames->size()); |
| 119 | 129 |
| 120 // Adjust padding for between decorations. | 130 // Adjust padding for between decorations. |
| 121 padding = DecorationHorizontalPad(); | 131 padding = DecorationHorizontalPad(); |
| 122 } | 132 } |
| 123 } | 133 } |
| 124 } | 134 } |
| 125 | 135 |
| 126 DCHECK_EQ(decorations->size(), decoration_frames->size()); | 136 DCHECK_EQ(decorations->size(), decoration_frames->size()); |
| 127 *remaining_frame = frame; | 137 *remaining_frame = frame; |
| 128 } | 138 } |
| 129 | 139 |
| 140 // Hide separators at the beginning and end of the decorator list. | |
| 141 void HideUnneededSeparators( | |
| 142 std::vector<LocationBarDecoration*>* decorations) { | |
| 143 if (!decorations->empty() && decorations->front()->AsSeparatorDecoration()) | |
| 144 decorations->erase(decorations->begin()); | |
| 145 if (!decorations->empty() && decorations->back()->AsSeparatorDecoration()) | |
| 146 decorations->pop_back(); | |
| 147 } | |
| 148 | |
| 130 // Helper function for calculating placement of decorations w/in the cell. | 149 // Helper function for calculating placement of decorations w/in the cell. |
| 131 // |frame| is the cell's boundary rectangle, |remaining_frame| will get any | 150 // |frame| is the cell's boundary rectangle, |remaining_frame| will get any |
| 132 // space left after decorations are laid out (for text). |left_decorations| is | 151 // space left after decorations are laid out (for text). |left_decorations| is |
| 133 // a set of decorations for the left-hand side of the cell, |right_decorations| | 152 // a set of decorations for the left-hand side of the cell, |right_decorations| |
| 134 // for the right-hand side. |edge_width| is the width of one vertical edge of | 153 // for the right-hand side. |edge_width| is the width of one vertical edge of |
| 135 // the omnibox, this depends on whether the display is low DPI or high DPI. | 154 // the omnibox, this depends on whether the display is low DPI or high DPI. |
| 136 // |decorations| will contain the resulting visible decorations, and | 155 // |decorations| will contain the resulting visible decorations, and |
| 137 // |decoration_frames| will contain their frames in the same coordinates as | 156 // |decoration_frames| will contain their frames in the same coordinates as |
| 138 // |frame|. Decorations will be ordered left to right. As a convenience returns | 157 // |frame|. Decorations will be ordered left to right. As a convenience returns |
| 139 // the index of the first right-hand decoration. | 158 // the index of the first right-hand decoration. |
| 140 size_t CalculatePositionsInFrame( | 159 size_t CalculatePositionsInFrame( |
| 141 NSRect frame, | 160 NSRect frame, |
| 161 CGFloat text_width, | |
| 142 const std::vector<LocationBarDecoration*>& left_decorations, | 162 const std::vector<LocationBarDecoration*>& left_decorations, |
| 143 const std::vector<LocationBarDecoration*>& right_decorations, | 163 const std::vector<LocationBarDecoration*>& right_decorations, |
| 144 CGFloat edge_width, | 164 CGFloat edge_width, |
| 145 std::vector<LocationBarDecoration*>* decorations, | 165 std::vector<LocationBarDecoration*>* decorations, |
| 146 std::vector<NSRect>* decoration_frames, | 166 std::vector<NSRect>* decoration_frames, |
| 147 NSRect* remaining_frame) { | 167 NSRect* remaining_frame) { |
| 148 decorations->clear(); | 168 decorations->clear(); |
| 149 decoration_frames->clear(); | 169 decoration_frames->clear(); |
| 150 | 170 |
| 151 // Layout |left_decorations| against the LHS. | 171 // Layout |left_decorations| against the LHS. |
| 152 CalculatePositionsHelper(frame, left_decorations, NSMinXEdge, | 172 { |
| 153 kLeftDecorationXOffset, kLeftDecorationXOffset, | 173 std::vector<LocationBarDecoration*> result_decorations; |
| 154 decorations, decoration_frames, &frame); | 174 std::vector<NSRect> result_frames; |
| 155 DCHECK_EQ(decorations->size(), decoration_frames->size()); | 175 NSRect result_frame = NSZeroRect; |
| 156 | 176 CalculatePositionsHelper(frame, text_width, left_decorations, NSMinXEdge, |
| 157 // Capture the number of visible left-hand decorations. | 177 kLeftDecorationXOffset, kLeftDecorationXOffset, |
| 178 &result_decorations, &result_frames, | |
| 179 &result_frame); | |
| 180 HideUnneededSeparators(&result_decorations); | |
|
Scott Hess - ex-Googler
2013/01/28 21:37:27
The helper already knows about applying auto-colla
sail
2013/01/29 22:31:08
The views code also does two passes.
I tried movin
Scott Hess - ex-Googler
2013/01/29 23:28:36
OK. My main concern is whether there will be subt
| |
| 181 CalculatePositionsHelper(frame, text_width, result_decorations, NSMinXEdge, | |
| 182 kLeftDecorationXOffset, kLeftDecorationXOffset, | |
| 183 decorations, decoration_frames, &frame); | |
| 184 } | |
| 158 const size_t left_count = decorations->size(); | 185 const size_t left_count = decorations->size(); |
| 159 | 186 |
| 160 // Layout |right_decorations| against the RHS. | 187 // Layout |right_decorations| against the RHS. |
| 161 CalculatePositionsHelper(frame, right_decorations, NSMaxXEdge, | 188 { |
| 162 RightDecorationXOffset(), edge_width, decorations, | 189 std::vector<LocationBarDecoration*> result_decorations; |
| 163 decoration_frames, &frame); | 190 std::vector<NSRect> result_frames; |
| 164 DCHECK_EQ(decorations->size(), decoration_frames->size()); | 191 NSRect result_frame = NSZeroRect; |
| 192 CalculatePositionsHelper(frame, text_width, right_decorations, NSMaxXEdge, | |
| 193 RightDecorationXOffset(), edge_width, | |
| 194 &result_decorations, &result_frames, | |
| 195 &result_frame); | |
| 196 HideUnneededSeparators(&result_decorations); | |
| 197 CalculatePositionsHelper(frame, text_width, result_decorations, NSMaxXEdge, | |
| 198 RightDecorationXOffset(), edge_width, | |
| 199 decorations, decoration_frames, &frame); | |
| 200 } | |
| 165 | 201 |
| 166 // Reverse the right-hand decorations so that overall everything is | 202 // Reverse the right-hand decorations so that overall everything is |
| 167 // sorted left to right. | 203 // sorted left to right. |
| 168 std::reverse(decorations->begin() + left_count, decorations->end()); | 204 std::reverse(decorations->begin() + left_count, decorations->end()); |
| 169 std::reverse(decoration_frames->begin() + left_count, | 205 std::reverse(decoration_frames->begin() + left_count, |
| 170 decoration_frames->end()); | 206 decoration_frames->end()); |
| 171 | 207 |
| 172 *remaining_frame = frame; | 208 *remaining_frame = frame; |
| 173 if (FeatureSwitch::script_badges()->IsEnabled()) { | 209 if (FeatureSwitch::script_badges()->IsEnabled()) { |
| 174 // Keep the padding distance between the right-most decoration and the edit | 210 // Keep the padding distance between the right-most decoration and the edit |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 212 } | 248 } |
| 213 | 249 |
| 214 - (void)addRightDecoration:(LocationBarDecoration*)decoration { | 250 - (void)addRightDecoration:(LocationBarDecoration*)decoration { |
| 215 rightDecorations_.push_back(decoration); | 251 rightDecorations_.push_back(decoration); |
| 216 } | 252 } |
| 217 | 253 |
| 218 - (CGFloat)availableWidthInFrame:(const NSRect)frame { | 254 - (CGFloat)availableWidthInFrame:(const NSRect)frame { |
| 219 std::vector<LocationBarDecoration*> decorations; | 255 std::vector<LocationBarDecoration*> decorations; |
| 220 std::vector<NSRect> decorationFrames; | 256 std::vector<NSRect> decorationFrames; |
| 221 NSRect textFrame; | 257 NSRect textFrame; |
| 222 CalculatePositionsInFrame(frame, leftDecorations_, rightDecorations_, | 258 NSAttributedString* text = [self attributedStringValue]; |
|
Scott Hess - ex-Googler
2013/01/28 21:37:27
Suggest either a helper for "[[self attributedStri
sail
2013/01/29 22:31:08
Done.
Added a helper method -[AutocompleteTextFiel
| |
| 223 [self edgeWidth], &decorations, &decorationFrames, | 259 CalculatePositionsInFrame(frame, [text size].width, leftDecorations_, |
| 224 &textFrame); | 260 rightDecorations_, [self edgeWidth], &decorations, |
| 261 &decorationFrames, &textFrame); | |
| 225 | 262 |
| 226 return NSWidth(textFrame); | 263 return NSWidth(textFrame); |
| 227 } | 264 } |
| 228 | 265 |
| 229 - (NSRect)frameForDecoration:(const LocationBarDecoration*)aDecoration | 266 - (NSRect)frameForDecoration:(const LocationBarDecoration*)aDecoration |
| 230 inFrame:(NSRect)cellFrame { | 267 inFrame:(NSRect)cellFrame { |
| 231 // Short-circuit if the decoration is known to be not visible. | 268 // Short-circuit if the decoration is known to be not visible. |
| 232 if (aDecoration && !aDecoration->IsVisible()) | 269 if (aDecoration && !aDecoration->IsVisible()) |
| 233 return NSZeroRect; | 270 return NSZeroRect; |
| 234 | 271 |
| 235 // Layout the decorations. | 272 // Layout the decorations. |
| 236 std::vector<LocationBarDecoration*> decorations; | 273 std::vector<LocationBarDecoration*> decorations; |
| 237 std::vector<NSRect> decorationFrames; | 274 std::vector<NSRect> decorationFrames; |
| 238 NSRect textFrame; | 275 NSRect textFrame; |
| 239 CalculatePositionsInFrame(cellFrame, leftDecorations_, rightDecorations_, | 276 NSAttributedString* text = [self attributedStringValue]; |
| 240 [self edgeWidth], &decorations, &decorationFrames, | 277 CalculatePositionsInFrame(cellFrame, [text size].width, leftDecorations_, |
| 241 &textFrame); | 278 rightDecorations_, [self edgeWidth], &decorations, |
| 279 &decorationFrames, &textFrame); | |
| 242 | 280 |
| 243 // Find our decoration and return the corresponding frame. | 281 // Find our decoration and return the corresponding frame. |
| 244 std::vector<LocationBarDecoration*>::const_iterator iter = | 282 std::vector<LocationBarDecoration*>::const_iterator iter = |
| 245 std::find(decorations.begin(), decorations.end(), aDecoration); | 283 std::find(decorations.begin(), decorations.end(), aDecoration); |
| 246 if (iter != decorations.end()) { | 284 if (iter != decorations.end()) { |
| 247 const size_t index = iter - decorations.begin(); | 285 const size_t index = iter - decorations.begin(); |
| 248 return decorationFrames[index]; | 286 return decorationFrames[index]; |
| 249 } | 287 } |
| 250 | 288 |
| 251 // Decorations which are not visible should have been filtered out | 289 // The decoration is marked as visible but was either collapsed or hidden. |
| 252 // at the top, but return |NSZeroRect| rather than a 0-width rect | |
| 253 // for consistency. | |
| 254 NOTREACHED(); | |
| 255 return NSZeroRect; | 290 return NSZeroRect; |
| 256 } | 291 } |
| 257 | 292 |
| 258 // Overriden to account for the decorations. | 293 // Overriden to account for the decorations. |
| 259 - (NSRect)textFrameForFrame:(NSRect)cellFrame { | 294 - (NSRect)textFrameForFrame:(NSRect)cellFrame { |
| 295 NSAttributedString* text = [self attributedStringValue]; | |
| 296 | |
| 260 // Get the frame adjusted for decorations. | 297 // Get the frame adjusted for decorations. |
| 261 std::vector<LocationBarDecoration*> decorations; | 298 std::vector<LocationBarDecoration*> decorations; |
| 262 std::vector<NSRect> decorationFrames; | 299 std::vector<NSRect> decorationFrames; |
| 263 NSRect textFrame = [super textFrameForFrame:cellFrame]; | 300 NSRect textFrame = [super textFrameForFrame:cellFrame]; |
| 264 CalculatePositionsInFrame(textFrame, leftDecorations_, rightDecorations_, | 301 CalculatePositionsInFrame(textFrame, [text size].width, leftDecorations_, |
| 265 [self edgeWidth], &decorations, &decorationFrames, | 302 rightDecorations_, [self edgeWidth], &decorations, |
| 266 &textFrame); | 303 &decorationFrames, &textFrame); |
| 267 | 304 |
| 268 // NOTE: This function must closely match the logic in | 305 // NOTE: This function must closely match the logic in |
| 269 // |-drawInteriorWithFrame:inView:|. | 306 // |-drawInteriorWithFrame:inView:|. |
| 270 | 307 |
| 271 return textFrame; | 308 return textFrame; |
| 272 } | 309 } |
| 273 | 310 |
| 274 // Returns the sub-frame where clicks can happen within the cell. | 311 // Returns the sub-frame where clicks can happen within the cell. |
| 275 - (NSRect)clickableFrameForFrame:(NSRect)cellFrame { | 312 - (NSRect)clickableFrameForFrame:(NSRect)cellFrame { |
| 276 return [super textFrameForFrame:cellFrame]; | 313 return [super textFrameForFrame:cellFrame]; |
| 277 } | 314 } |
| 278 | 315 |
| 279 - (NSRect)textCursorFrameForFrame:(NSRect)cellFrame { | 316 - (NSRect)textCursorFrameForFrame:(NSRect)cellFrame { |
| 317 NSAttributedString* text = [self attributedStringValue]; | |
| 280 std::vector<LocationBarDecoration*> decorations; | 318 std::vector<LocationBarDecoration*> decorations; |
| 281 std::vector<NSRect> decorationFrames; | 319 std::vector<NSRect> decorationFrames; |
| 282 NSRect textFrame; | 320 NSRect textFrame; |
| 283 size_t left_count = | 321 size_t left_count = CalculatePositionsInFrame( |
| 284 CalculatePositionsInFrame(cellFrame, leftDecorations_, rightDecorations_, | 322 cellFrame, [text size].width, leftDecorations_, rightDecorations_, |
| 285 [self edgeWidth], &decorations, | 323 [self edgeWidth], &decorations, &decorationFrames, &textFrame); |
| 286 &decorationFrames, &textFrame); | |
| 287 | 324 |
| 288 // Determine the left-most extent for the i-beam cursor. | 325 // Determine the left-most extent for the i-beam cursor. |
| 289 CGFloat minX = NSMinX(textFrame); | 326 CGFloat minX = NSMinX(textFrame); |
| 290 for (size_t index = left_count; index--; ) { | 327 for (size_t index = left_count; index--; ) { |
| 291 if (decorations[index]->AcceptsMousePress()) | 328 if (decorations[index]->AcceptsMousePress()) |
| 292 break; | 329 break; |
| 293 | 330 |
| 294 // If at leftmost decoration, expand to edge of cell. | 331 // If at leftmost decoration, expand to edge of cell. |
| 295 if (!index) { | 332 if (!index) { |
| 296 minX = NSMinX(cellFrame); | 333 minX = NSMinX(cellFrame); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 315 | 352 |
| 316 // I-beam cursor covers left-most to right-most. | 353 // I-beam cursor covers left-most to right-most. |
| 317 return NSMakeRect(minX, NSMinY(textFrame), maxX - minX, NSHeight(textFrame)); | 354 return NSMakeRect(minX, NSMinY(textFrame), maxX - minX, NSHeight(textFrame)); |
| 318 } | 355 } |
| 319 | 356 |
| 320 - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { | 357 - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { |
| 321 std::vector<LocationBarDecoration*> decorations; | 358 std::vector<LocationBarDecoration*> decorations; |
| 322 std::vector<NSRect> decorationFrames; | 359 std::vector<NSRect> decorationFrames; |
| 323 NSRect workingFrame; | 360 NSRect workingFrame; |
| 324 | 361 |
| 325 CalculatePositionsInFrame(cellFrame, leftDecorations_, rightDecorations_, | 362 NSAttributedString* text = [self attributedStringValue]; |
| 326 [self edgeWidth], &decorations, &decorationFrames, | 363 CalculatePositionsInFrame(cellFrame, [text size].width, leftDecorations_, |
| 327 &workingFrame); | 364 rightDecorations_, [self edgeWidth], &decorations, |
| 365 &decorationFrames, &workingFrame); | |
| 328 | 366 |
| 329 // Draw the decorations. | 367 // Draw the decorations. |
| 330 for (size_t i = 0; i < decorations.size(); ++i) { | 368 for (size_t i = 0; i < decorations.size(); ++i) { |
| 331 if (decorations[i]) { | 369 if (decorations[i]) { |
| 332 NSRect background_frame = NSInsetRect( | 370 NSRect background_frame = NSInsetRect( |
| 333 decorationFrames[i], -(DecorationHorizontalPad() + 1) / 2, 2); | 371 decorationFrames[i], -(DecorationHorizontalPad() + 1) / 2, 2); |
| 334 decorations[i]->DrawWithBackgroundInFrame( | 372 decorations[i]->DrawWithBackgroundInFrame( |
| 335 background_frame, decorationFrames[i], controlView); | 373 background_frame, decorationFrames[i], controlView); |
| 336 } | 374 } |
| 337 } | 375 } |
| 338 | 376 |
| 339 // NOTE: This function must closely match the logic in | 377 // NOTE: This function must closely match the logic in |
| 340 // |-textFrameForFrame:|. | 378 // |-textFrameForFrame:|. |
| 341 | 379 |
| 342 // Superclass draws text portion WRT original |cellFrame|. | 380 // Superclass draws text portion WRT original |cellFrame|. |
| 343 [super drawInteriorWithFrame:cellFrame inView:controlView]; | 381 [super drawInteriorWithFrame:cellFrame inView:controlView]; |
| 344 } | 382 } |
| 345 | 383 |
| 346 - (LocationBarDecoration*)decorationForEvent:(NSEvent*)theEvent | 384 - (LocationBarDecoration*)decorationForEvent:(NSEvent*)theEvent |
| 347 inRect:(NSRect)cellFrame | 385 inRect:(NSRect)cellFrame |
| 348 ofView:(AutocompleteTextField*)controlView | 386 ofView:(AutocompleteTextField*)controlView |
| 349 { | 387 { |
| 350 const BOOL flipped = [controlView isFlipped]; | 388 const BOOL flipped = [controlView isFlipped]; |
| 351 const NSPoint location = | 389 const NSPoint location = |
| 352 [controlView convertPoint:[theEvent locationInWindow] fromView:nil]; | 390 [controlView convertPoint:[theEvent locationInWindow] fromView:nil]; |
| 391 NSAttributedString* text = [self attributedStringValue]; | |
| 353 | 392 |
| 354 std::vector<LocationBarDecoration*> decorations; | 393 std::vector<LocationBarDecoration*> decorations; |
| 355 std::vector<NSRect> decorationFrames; | 394 std::vector<NSRect> decorationFrames; |
| 356 NSRect textFrame; | 395 NSRect textFrame; |
| 357 CalculatePositionsInFrame(cellFrame, leftDecorations_, rightDecorations_, | 396 CalculatePositionsInFrame(cellFrame, [text size].width, leftDecorations_, |
| 397 rightDecorations_, | |
| 358 [self edgeWidth], &decorations, &decorationFrames, | 398 [self edgeWidth], &decorations, &decorationFrames, |
| 359 &textFrame); | 399 &textFrame); |
| 360 | 400 |
| 361 for (size_t i = 0; i < decorations.size(); ++i) { | 401 for (size_t i = 0; i < decorations.size(); ++i) { |
| 362 if (NSMouseInRect(location, decorationFrames[i], flipped)) | 402 if (NSMouseInRect(location, decorationFrames[i], flipped)) |
| 363 return decorations[i]; | 403 return decorations[i]; |
| 364 } | 404 } |
| 365 | 405 |
| 366 return NULL; | 406 return NULL; |
| 367 } | 407 } |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 500 decoration->SetButtonState(ButtonDecoration::kButtonStateNormal); | 540 decoration->SetButtonState(ButtonDecoration::kButtonStateNormal); |
| 501 [controlView setNeedsDisplay:YES]; | 541 [controlView setNeedsDisplay:YES]; |
| 502 } | 542 } |
| 503 } | 543 } |
| 504 | 544 |
| 505 - (void)setUpTrackingAreasInRect:(NSRect)frame | 545 - (void)setUpTrackingAreasInRect:(NSRect)frame |
| 506 ofView:(AutocompleteTextField*)view { | 546 ofView:(AutocompleteTextField*)view { |
| 507 std::vector<LocationBarDecoration*> decorations; | 547 std::vector<LocationBarDecoration*> decorations; |
| 508 std::vector<NSRect> decorationFrames; | 548 std::vector<NSRect> decorationFrames; |
| 509 NSRect textFrame; | 549 NSRect textFrame; |
| 550 NSAttributedString* text = [self attributedStringValue]; | |
| 510 NSRect cellRect = [self clickableFrameForFrame:[view bounds]]; | 551 NSRect cellRect = [self clickableFrameForFrame:[view bounds]]; |
| 511 CalculatePositionsInFrame(cellRect, leftDecorations_, rightDecorations_, | 552 CalculatePositionsInFrame(cellRect, [text size].width, leftDecorations_, |
| 512 [self edgeWidth], &decorations, &decorationFrames, | 553 rightDecorations_, [self edgeWidth], &decorations, |
| 513 &textFrame); | 554 &decorationFrames, &textFrame); |
| 514 | 555 |
| 515 // Remove previously-registered tracking areas, since we'll update them below. | 556 // Remove previously-registered tracking areas, since we'll update them below. |
| 516 for (CrTrackingArea* area in [view trackingAreas]) { | 557 for (CrTrackingArea* area in [view trackingAreas]) { |
| 517 if ([[area userInfo] objectForKey:kButtonDecorationKey]) | 558 if ([[area userInfo] objectForKey:kButtonDecorationKey]) |
| 518 [view removeTrackingArea:area]; | 559 [view removeTrackingArea:area]; |
| 519 } | 560 } |
| 520 | 561 |
| 521 // Setup new tracking areas for the buttons. | 562 // Setup new tracking areas for the buttons. |
| 522 for (size_t i = 0; i < decorations.size(); ++i) { | 563 for (size_t i = 0; i < decorations.size(); ++i) { |
| 523 ButtonDecoration* button = decorations[i]->AsButtonDecoration(); | 564 ButtonDecoration* button = decorations[i]->AsButtonDecoration(); |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 718 | 759 |
| 719 - (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)isLocal { | 760 - (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)isLocal { |
| 720 return NSDragOperationCopy; | 761 return NSDragOperationCopy; |
| 721 } | 762 } |
| 722 | 763 |
| 723 - (void)updateToolTipsInRect:(NSRect)cellFrame | 764 - (void)updateToolTipsInRect:(NSRect)cellFrame |
| 724 ofView:(AutocompleteTextField*)controlView { | 765 ofView:(AutocompleteTextField*)controlView { |
| 725 std::vector<LocationBarDecoration*> decorations; | 766 std::vector<LocationBarDecoration*> decorations; |
| 726 std::vector<NSRect> decorationFrames; | 767 std::vector<NSRect> decorationFrames; |
| 727 NSRect textFrame; | 768 NSRect textFrame; |
| 728 CalculatePositionsInFrame(cellFrame, leftDecorations_, rightDecorations_, | 769 NSAttributedString* text = [self attributedStringValue]; |
| 729 [self edgeWidth], &decorations, &decorationFrames, | 770 CalculatePositionsInFrame(cellFrame, [text size].width, leftDecorations_, |
| 730 &textFrame); | 771 rightDecorations_, [self edgeWidth], &decorations, |
| 772 &decorationFrames, &textFrame); | |
| 731 | 773 |
| 732 for (size_t i = 0; i < decorations.size(); ++i) { | 774 for (size_t i = 0; i < decorations.size(); ++i) { |
| 733 NSString* tooltip = decorations[i]->GetToolTip(); | 775 NSString* tooltip = decorations[i]->GetToolTip(); |
| 734 if ([tooltip length] > 0) | 776 if ([tooltip length] > 0) |
| 735 [controlView addToolTip:tooltip forRect:decorationFrames[i]]; | 777 [controlView addToolTip:tooltip forRect:decorationFrames[i]]; |
| 736 } | 778 } |
| 737 } | 779 } |
| 738 | 780 |
| 739 - (BOOL)hideFocusState { | 781 - (BOOL)hideFocusState { |
| 740 return hideFocusState_; | 782 return hideFocusState_; |
| 741 } | 783 } |
| 742 | 784 |
| 743 - (void)setHideFocusState:(BOOL)hideFocusState | 785 - (void)setHideFocusState:(BOOL)hideFocusState |
| 744 ofView:(AutocompleteTextField*)controlView { | 786 ofView:(AutocompleteTextField*)controlView { |
| 745 if (hideFocusState_ == hideFocusState) | 787 if (hideFocusState_ == hideFocusState) |
| 746 return; | 788 return; |
| 747 hideFocusState_ = hideFocusState; | 789 hideFocusState_ = hideFocusState; |
| 748 [controlView setNeedsDisplay:YES]; | 790 [controlView setNeedsDisplay:YES]; |
| 749 NSTextView* fieldEditor = | 791 NSTextView* fieldEditor = |
| 750 base::mac::ObjCCastStrict<NSTextView>([controlView currentEditor]); | 792 base::mac::ObjCCastStrict<NSTextView>([controlView currentEditor]); |
| 751 [fieldEditor updateInsertionPointStateAndRestartTimer:YES]; | 793 [fieldEditor updateInsertionPointStateAndRestartTimer:YES]; |
| 752 } | 794 } |
| 753 | 795 |
| 754 - (BOOL)showsFirstResponder { | 796 - (BOOL)showsFirstResponder { |
| 755 return [super showsFirstResponder] && !hideFocusState_; | 797 return [super showsFirstResponder] && !hideFocusState_; |
| 756 } | 798 } |
| 757 | 799 |
| 758 @end | 800 @end |
| OLD | NEW |