| 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" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 // visible and which fit, in the same order as |all_decorations|, | 64 // visible and which fit, in the same order as |all_decorations|, |
| 65 // while |decoration_frames| will be the corresponding frames. | 65 // while |decoration_frames| will be the corresponding frames. |
| 66 // |x_edge| describes the edge to layout the decorations against | 66 // |x_edge| describes the edge to layout the decorations against |
| 67 // (|NSMinXEdge| or |NSMaxXEdge|). |regular_padding| is the padding | 67 // (|NSMinXEdge| or |NSMaxXEdge|). |regular_padding| is the padding |
| 68 // from the edge of |cell_frame| to use when the first visible decoration | 68 // 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 | 69 // 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. | 70 // first decoration is a button decoration, ie. the action box button. |
| 71 // (|DecorationHorizontalPad()| is used between decorations). | 71 // (|DecorationHorizontalPad()| is used between decorations). |
| 72 void CalculatePositionsHelper( | 72 void CalculatePositionsHelper( |
| 73 NSRect frame, | 73 NSRect frame, |
| 74 CGFloat text_width, |
| 74 const std::vector<LocationBarDecoration*>& all_decorations, | 75 const std::vector<LocationBarDecoration*>& all_decorations, |
| 75 NSRectEdge x_edge, | 76 NSRectEdge x_edge, |
| 76 CGFloat regular_padding, | 77 CGFloat regular_padding, |
| 77 CGFloat action_padding, | 78 CGFloat action_padding, |
| 78 std::vector<LocationBarDecoration*>* decorations, | 79 std::vector<LocationBarDecoration*>* decorations, |
| 79 std::vector<NSRect>* decoration_frames, | 80 std::vector<NSRect>* decoration_frames, |
| 80 NSRect* remaining_frame) { | 81 NSRect* remaining_frame) { |
| 81 DCHECK(x_edge == NSMinXEdge || x_edge == NSMaxXEdge); | 82 DCHECK(x_edge == NSMinXEdge || x_edge == NSMaxXEdge); |
| 82 DCHECK_EQ(decorations->size(), decoration_frames->size()); | 83 DCHECK_EQ(decorations->size(), decoration_frames->size()); |
| 83 | 84 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 95 } | 96 } |
| 96 | 97 |
| 97 NSRect padding_rect, available; | 98 NSRect padding_rect, available; |
| 98 | 99 |
| 99 // Peel off the outside padding. | 100 // Peel off the outside padding. |
| 100 NSDivideRect(frame, &padding_rect, &available, padding, x_edge); | 101 NSDivideRect(frame, &padding_rect, &available, padding, x_edge); |
| 101 | 102 |
| 102 // Find out how large the decoration will be in the remaining | 103 // Find out how large the decoration will be in the remaining |
| 103 // space. | 104 // space. |
| 104 const CGFloat used_width = | 105 const CGFloat used_width = |
| 105 all_decorations[i]->GetWidthForSpace(NSWidth(available)); | 106 all_decorations[i]->GetWidthForSpace(NSWidth(available), text_width); |
| 106 | 107 |
| 107 if (used_width != LocationBarDecoration::kOmittedWidth) { | 108 if (used_width != LocationBarDecoration::kOmittedWidth) { |
| 108 DCHECK_GT(used_width, 0.0); | 109 DCHECK_GT(used_width, 0.0); |
| 109 NSRect decoration_frame; | 110 NSRect decoration_frame; |
| 110 | 111 |
| 111 // Peel off the desired width, leaving the remainder in | 112 // Peel off the desired width, leaving the remainder in |
| 112 // |frame|. | 113 // |frame|. |
| 113 NSDivideRect(available, &decoration_frame, &frame, | 114 NSDivideRect(available, &decoration_frame, &frame, |
| 114 used_width, x_edge); | 115 used_width, x_edge); |
| 115 | 116 |
| 116 decorations->push_back(all_decorations[i]); | 117 decorations->push_back(all_decorations[i]); |
| 117 decoration_frames->push_back(decoration_frame); | 118 decoration_frames->push_back(decoration_frame); |
| 118 DCHECK_EQ(decorations->size(), decoration_frames->size()); | 119 DCHECK_EQ(decorations->size(), decoration_frames->size()); |
| 119 | 120 |
| 120 // Adjust padding for between decorations. | 121 // Adjust padding for between decorations. |
| 121 padding = DecorationHorizontalPad(); | 122 padding = DecorationHorizontalPad(); |
| 122 } | 123 } |
| 123 } | 124 } |
| 124 } | 125 } |
| 125 | 126 |
| 126 DCHECK_EQ(decorations->size(), decoration_frames->size()); | 127 DCHECK_EQ(decorations->size(), decoration_frames->size()); |
| 127 *remaining_frame = frame; | 128 *remaining_frame = frame; |
| 128 } | 129 } |
| 129 | 130 |
| 131 // Hide separators at the beginning and end of the decorator list. |
| 132 void HideUnneededSeparators( |
| 133 std::vector<LocationBarDecoration*>* decorations) { |
| 134 if (!decorations->empty() && decorations->back()->IsSeparator()) |
| 135 decorations->pop_back(); |
| 136 if (!decorations->empty() && decorations->front()->IsSeparator()) |
| 137 decorations->erase(decorations->begin()); |
| 138 } |
| 139 |
| 130 // Helper function for calculating placement of decorations w/in the cell. | 140 // Helper function for calculating placement of decorations w/in the cell. |
| 131 // |frame| is the cell's boundary rectangle, |remaining_frame| will get any | 141 // |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 | 142 // 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| | 143 // 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 | 144 // 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. | 145 // the omnibox, this depends on whether the display is low DPI or high DPI. |
| 136 // |decorations| will contain the resulting visible decorations, and | 146 // |decorations| will contain the resulting visible decorations, and |
| 137 // |decoration_frames| will contain their frames in the same coordinates as | 147 // |decoration_frames| will contain their frames in the same coordinates as |
| 138 // |frame|. Decorations will be ordered left to right. As a convenience returns | 148 // |frame|. Decorations will be ordered left to right. As a convenience returns |
| 139 // the index of the first right-hand decoration. | 149 // the index of the first right-hand decoration. |
| 140 size_t CalculatePositionsInFrame( | 150 size_t CalculatePositionsInFrame( |
| 141 NSRect frame, | 151 NSRect frame, |
| 152 CGFloat text_width, |
| 142 const std::vector<LocationBarDecoration*>& left_decorations, | 153 const std::vector<LocationBarDecoration*>& left_decorations, |
| 143 const std::vector<LocationBarDecoration*>& right_decorations, | 154 const std::vector<LocationBarDecoration*>& right_decorations, |
| 144 CGFloat edge_width, | 155 CGFloat edge_width, |
| 145 std::vector<LocationBarDecoration*>* decorations, | 156 std::vector<LocationBarDecoration*>* decorations, |
| 146 std::vector<NSRect>* decoration_frames, | 157 std::vector<NSRect>* decoration_frames, |
| 147 NSRect* remaining_frame) { | 158 NSRect* remaining_frame) { |
| 148 decorations->clear(); | 159 decorations->clear(); |
| 149 decoration_frames->clear(); | 160 decoration_frames->clear(); |
| 150 | 161 |
| 151 // Layout |left_decorations| against the LHS. | 162 // Layout |left_decorations| against the LHS. |
| 152 CalculatePositionsHelper(frame, left_decorations, NSMinXEdge, | 163 { |
| 153 kLeftDecorationXOffset, kLeftDecorationXOffset, | 164 std::vector<LocationBarDecoration*> result_decorations; |
| 154 decorations, decoration_frames, &frame); | 165 std::vector<NSRect> result_frames; |
| 155 DCHECK_EQ(decorations->size(), decoration_frames->size()); | 166 NSRect result_frame = NSZeroRect; |
| 156 | 167 CalculatePositionsHelper(frame, text_width, left_decorations, NSMinXEdge, |
| 157 // Capture the number of visible left-hand decorations. | 168 kLeftDecorationXOffset, kLeftDecorationXOffset, |
| 169 &result_decorations, &result_frames, |
| 170 &result_frame); |
| 171 HideUnneededSeparators(&result_decorations); |
| 172 CalculatePositionsHelper(frame, text_width, result_decorations, NSMinXEdge, |
| 173 kLeftDecorationXOffset, kLeftDecorationXOffset, |
| 174 decorations, decoration_frames, &frame); |
| 175 } |
| 158 const size_t left_count = decorations->size(); | 176 const size_t left_count = decorations->size(); |
| 159 | 177 |
| 160 // Layout |right_decorations| against the RHS. | 178 // Layout |right_decorations| against the RHS. |
| 161 CalculatePositionsHelper(frame, right_decorations, NSMaxXEdge, | 179 { |
| 162 RightDecorationXOffset(), edge_width, decorations, | 180 std::vector<LocationBarDecoration*> result_decorations; |
| 163 decoration_frames, &frame); | 181 std::vector<NSRect> result_frames; |
| 164 DCHECK_EQ(decorations->size(), decoration_frames->size()); | 182 NSRect result_frame = NSZeroRect; |
| 183 CalculatePositionsHelper(frame, text_width, right_decorations, NSMaxXEdge, |
| 184 RightDecorationXOffset(), edge_width, |
| 185 &result_decorations, &result_frames, |
| 186 &result_frame); |
| 187 HideUnneededSeparators(&result_decorations); |
| 188 CalculatePositionsHelper(frame, text_width, result_decorations, NSMaxXEdge, |
| 189 RightDecorationXOffset(), edge_width, |
| 190 decorations, decoration_frames, &frame); |
| 191 } |
| 165 | 192 |
| 166 // Reverse the right-hand decorations so that overall everything is | 193 // Reverse the right-hand decorations so that overall everything is |
| 167 // sorted left to right. | 194 // sorted left to right. |
| 168 std::reverse(decorations->begin() + left_count, decorations->end()); | 195 std::reverse(decorations->begin() + left_count, decorations->end()); |
| 169 std::reverse(decoration_frames->begin() + left_count, | 196 std::reverse(decoration_frames->begin() + left_count, |
| 170 decoration_frames->end()); | 197 decoration_frames->end()); |
| 171 | 198 |
| 172 *remaining_frame = frame; | 199 *remaining_frame = frame; |
| 173 if (FeatureSwitch::script_badges()->IsEnabled()) { | 200 if (FeatureSwitch::script_badges()->IsEnabled()) { |
| 174 // Keep the padding distance between the right-most decoration and the edit | 201 // Keep the padding distance between the right-most decoration and the edit |
| 175 // box, so that any decoration background isn't overwritten by the edit | 202 // box, so that any decoration background isn't overwritten by the edit |
| 176 // box's background. | 203 // box's background. |
| 177 NSRect dummy; | 204 NSRect dummy; |
| 178 NSDivideRect(frame, &dummy, remaining_frame, | 205 NSDivideRect(frame, &dummy, remaining_frame, |
| 179 DecorationHorizontalPad(), NSMaxXEdge); | 206 DecorationHorizontalPad(), NSMaxXEdge); |
| 180 } | 207 } |
| 181 return left_count; | 208 return left_count; |
| 182 } | 209 } |
| 183 | 210 |
| 184 } // namespace | 211 } // namespace |
| 185 | 212 |
| 213 @interface AutocompleteTextFieldCell () |
| 214 - (CGFloat)textWidth; |
| 215 @end |
| 216 |
| 186 @implementation AutocompleteTextFieldCell | 217 @implementation AutocompleteTextFieldCell |
| 187 | 218 |
| 188 - (CGFloat)baselineAdjust { | 219 - (CGFloat)baselineAdjust { |
| 189 return kBaselineAdjust; | 220 return kBaselineAdjust; |
| 190 } | 221 } |
| 191 | 222 |
| 192 - (CGFloat)cornerRadius { | 223 - (CGFloat)cornerRadius { |
| 193 return kCornerRadius; | 224 return kCornerRadius; |
| 194 } | 225 } |
| 195 | 226 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 212 } | 243 } |
| 213 | 244 |
| 214 - (void)addRightDecoration:(LocationBarDecoration*)decoration { | 245 - (void)addRightDecoration:(LocationBarDecoration*)decoration { |
| 215 rightDecorations_.push_back(decoration); | 246 rightDecorations_.push_back(decoration); |
| 216 } | 247 } |
| 217 | 248 |
| 218 - (CGFloat)availableWidthInFrame:(const NSRect)frame { | 249 - (CGFloat)availableWidthInFrame:(const NSRect)frame { |
| 219 std::vector<LocationBarDecoration*> decorations; | 250 std::vector<LocationBarDecoration*> decorations; |
| 220 std::vector<NSRect> decorationFrames; | 251 std::vector<NSRect> decorationFrames; |
| 221 NSRect textFrame; | 252 NSRect textFrame; |
| 222 CalculatePositionsInFrame(frame, leftDecorations_, rightDecorations_, | 253 CalculatePositionsInFrame(frame, [self textWidth], leftDecorations_, |
| 223 [self edgeWidth], &decorations, &decorationFrames, | 254 rightDecorations_, [self edgeWidth], &decorations, |
| 224 &textFrame); | 255 &decorationFrames, &textFrame); |
| 225 | 256 |
| 226 return NSWidth(textFrame); | 257 return NSWidth(textFrame); |
| 227 } | 258 } |
| 228 | 259 |
| 229 - (NSRect)frameForDecoration:(const LocationBarDecoration*)aDecoration | 260 - (NSRect)frameForDecoration:(const LocationBarDecoration*)aDecoration |
| 230 inFrame:(NSRect)cellFrame { | 261 inFrame:(NSRect)cellFrame { |
| 231 // Short-circuit if the decoration is known to be not visible. | 262 // Short-circuit if the decoration is known to be not visible. |
| 232 if (aDecoration && !aDecoration->IsVisible()) | 263 if (aDecoration && !aDecoration->IsVisible()) |
| 233 return NSZeroRect; | 264 return NSZeroRect; |
| 234 | 265 |
| 235 // Layout the decorations. | 266 // Layout the decorations. |
| 236 std::vector<LocationBarDecoration*> decorations; | 267 std::vector<LocationBarDecoration*> decorations; |
| 237 std::vector<NSRect> decorationFrames; | 268 std::vector<NSRect> decorationFrames; |
| 238 NSRect textFrame; | 269 NSRect textFrame; |
| 239 CalculatePositionsInFrame(cellFrame, leftDecorations_, rightDecorations_, | 270 CalculatePositionsInFrame(cellFrame, [self textWidth], leftDecorations_, |
| 240 [self edgeWidth], &decorations, &decorationFrames, | 271 rightDecorations_, [self edgeWidth], &decorations, |
| 241 &textFrame); | 272 &decorationFrames, &textFrame); |
| 242 | 273 |
| 243 // Find our decoration and return the corresponding frame. | 274 // Find our decoration and return the corresponding frame. |
| 244 std::vector<LocationBarDecoration*>::const_iterator iter = | 275 std::vector<LocationBarDecoration*>::const_iterator iter = |
| 245 std::find(decorations.begin(), decorations.end(), aDecoration); | 276 std::find(decorations.begin(), decorations.end(), aDecoration); |
| 246 if (iter != decorations.end()) { | 277 if (iter != decorations.end()) { |
| 247 const size_t index = iter - decorations.begin(); | 278 const size_t index = iter - decorations.begin(); |
| 248 return decorationFrames[index]; | 279 return decorationFrames[index]; |
| 249 } | 280 } |
| 250 | 281 |
| 251 // Decorations which are not visible should have been filtered out | 282 // 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; | 283 return NSZeroRect; |
| 256 } | 284 } |
| 257 | 285 |
| 258 // Overriden to account for the decorations. | 286 // Overriden to account for the decorations. |
| 259 - (NSRect)textFrameForFrame:(NSRect)cellFrame { | 287 - (NSRect)textFrameForFrame:(NSRect)cellFrame { |
| 260 // Get the frame adjusted for decorations. | 288 // Get the frame adjusted for decorations. |
| 261 std::vector<LocationBarDecoration*> decorations; | 289 std::vector<LocationBarDecoration*> decorations; |
| 262 std::vector<NSRect> decorationFrames; | 290 std::vector<NSRect> decorationFrames; |
| 263 NSRect textFrame = [super textFrameForFrame:cellFrame]; | 291 NSRect textFrame = [super textFrameForFrame:cellFrame]; |
| 264 CalculatePositionsInFrame(textFrame, leftDecorations_, rightDecorations_, | 292 CalculatePositionsInFrame(textFrame, [self textWidth], leftDecorations_, |
| 265 [self edgeWidth], &decorations, &decorationFrames, | 293 rightDecorations_, [self edgeWidth], &decorations, |
| 266 &textFrame); | 294 &decorationFrames, &textFrame); |
| 267 | 295 |
| 268 // NOTE: This function must closely match the logic in | 296 // NOTE: This function must closely match the logic in |
| 269 // |-drawInteriorWithFrame:inView:|. | 297 // |-drawInteriorWithFrame:inView:|. |
| 270 | 298 |
| 271 return textFrame; | 299 return textFrame; |
| 272 } | 300 } |
| 273 | 301 |
| 274 // Returns the sub-frame where clicks can happen within the cell. | 302 // Returns the sub-frame where clicks can happen within the cell. |
| 275 - (NSRect)clickableFrameForFrame:(NSRect)cellFrame { | 303 - (NSRect)clickableFrameForFrame:(NSRect)cellFrame { |
| 276 return [super textFrameForFrame:cellFrame]; | 304 return [super textFrameForFrame:cellFrame]; |
| 277 } | 305 } |
| 278 | 306 |
| 279 - (NSRect)textCursorFrameForFrame:(NSRect)cellFrame { | 307 - (NSRect)textCursorFrameForFrame:(NSRect)cellFrame { |
| 280 std::vector<LocationBarDecoration*> decorations; | 308 std::vector<LocationBarDecoration*> decorations; |
| 281 std::vector<NSRect> decorationFrames; | 309 std::vector<NSRect> decorationFrames; |
| 282 NSRect textFrame; | 310 NSRect textFrame; |
| 283 size_t left_count = | 311 size_t left_count = CalculatePositionsInFrame( |
| 284 CalculatePositionsInFrame(cellFrame, leftDecorations_, rightDecorations_, | 312 cellFrame, [self textWidth], leftDecorations_, rightDecorations_, |
| 285 [self edgeWidth], &decorations, | 313 [self edgeWidth], &decorations, &decorationFrames, &textFrame); |
| 286 &decorationFrames, &textFrame); | |
| 287 | 314 |
| 288 // Determine the left-most extent for the i-beam cursor. | 315 // Determine the left-most extent for the i-beam cursor. |
| 289 CGFloat minX = NSMinX(textFrame); | 316 CGFloat minX = NSMinX(textFrame); |
| 290 for (size_t index = left_count; index--; ) { | 317 for (size_t index = left_count; index--; ) { |
| 291 if (decorations[index]->AcceptsMousePress()) | 318 if (decorations[index]->AcceptsMousePress()) |
| 292 break; | 319 break; |
| 293 | 320 |
| 294 // If at leftmost decoration, expand to edge of cell. | 321 // If at leftmost decoration, expand to edge of cell. |
| 295 if (!index) { | 322 if (!index) { |
| 296 minX = NSMinX(cellFrame); | 323 minX = NSMinX(cellFrame); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 315 | 342 |
| 316 // I-beam cursor covers left-most to right-most. | 343 // I-beam cursor covers left-most to right-most. |
| 317 return NSMakeRect(minX, NSMinY(textFrame), maxX - minX, NSHeight(textFrame)); | 344 return NSMakeRect(minX, NSMinY(textFrame), maxX - minX, NSHeight(textFrame)); |
| 318 } | 345 } |
| 319 | 346 |
| 320 - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { | 347 - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { |
| 321 std::vector<LocationBarDecoration*> decorations; | 348 std::vector<LocationBarDecoration*> decorations; |
| 322 std::vector<NSRect> decorationFrames; | 349 std::vector<NSRect> decorationFrames; |
| 323 NSRect workingFrame; | 350 NSRect workingFrame; |
| 324 | 351 |
| 325 CalculatePositionsInFrame(cellFrame, leftDecorations_, rightDecorations_, | 352 CalculatePositionsInFrame(cellFrame, [self textWidth], leftDecorations_, |
| 326 [self edgeWidth], &decorations, &decorationFrames, | 353 rightDecorations_, [self edgeWidth], &decorations, |
| 327 &workingFrame); | 354 &decorationFrames, &workingFrame); |
| 328 | 355 |
| 329 // Draw the decorations. | 356 // Draw the decorations. |
| 330 for (size_t i = 0; i < decorations.size(); ++i) { | 357 for (size_t i = 0; i < decorations.size(); ++i) { |
| 331 if (decorations[i]) { | 358 if (decorations[i]) { |
| 332 NSRect background_frame = NSInsetRect( | 359 NSRect background_frame = NSInsetRect( |
| 333 decorationFrames[i], -(DecorationHorizontalPad() + 1) / 2, 2); | 360 decorationFrames[i], -(DecorationHorizontalPad() + 1) / 2, 2); |
| 334 decorations[i]->DrawWithBackgroundInFrame( | 361 decorations[i]->DrawWithBackgroundInFrame( |
| 335 background_frame, decorationFrames[i], controlView); | 362 background_frame, decorationFrames[i], controlView); |
| 336 } | 363 } |
| 337 } | 364 } |
| 338 | 365 |
| 339 // NOTE: This function must closely match the logic in | 366 // NOTE: This function must closely match the logic in |
| 340 // |-textFrameForFrame:|. | 367 // |-textFrameForFrame:|. |
| 341 | 368 |
| 342 // Superclass draws text portion WRT original |cellFrame|. | 369 // Superclass draws text portion WRT original |cellFrame|. |
| 343 [super drawInteriorWithFrame:cellFrame inView:controlView]; | 370 [super drawInteriorWithFrame:cellFrame inView:controlView]; |
| 344 } | 371 } |
| 345 | 372 |
| 346 - (LocationBarDecoration*)decorationForEvent:(NSEvent*)theEvent | 373 - (LocationBarDecoration*)decorationForEvent:(NSEvent*)theEvent |
| 347 inRect:(NSRect)cellFrame | 374 inRect:(NSRect)cellFrame |
| 348 ofView:(AutocompleteTextField*)controlView | 375 ofView:(AutocompleteTextField*)controlView |
| 349 { | 376 { |
| 350 const BOOL flipped = [controlView isFlipped]; | 377 const BOOL flipped = [controlView isFlipped]; |
| 351 const NSPoint location = | 378 const NSPoint location = |
| 352 [controlView convertPoint:[theEvent locationInWindow] fromView:nil]; | 379 [controlView convertPoint:[theEvent locationInWindow] fromView:nil]; |
| 353 | 380 |
| 354 std::vector<LocationBarDecoration*> decorations; | 381 std::vector<LocationBarDecoration*> decorations; |
| 355 std::vector<NSRect> decorationFrames; | 382 std::vector<NSRect> decorationFrames; |
| 356 NSRect textFrame; | 383 NSRect textFrame; |
| 357 CalculatePositionsInFrame(cellFrame, leftDecorations_, rightDecorations_, | 384 CalculatePositionsInFrame(cellFrame, [self textWidth], leftDecorations_, |
| 358 [self edgeWidth], &decorations, &decorationFrames, | 385 rightDecorations_, [self edgeWidth], &decorations, |
| 359 &textFrame); | 386 &decorationFrames, &textFrame); |
| 360 | 387 |
| 361 for (size_t i = 0; i < decorations.size(); ++i) { | 388 for (size_t i = 0; i < decorations.size(); ++i) { |
| 362 if (NSMouseInRect(location, decorationFrames[i], flipped)) | 389 if (NSMouseInRect(location, decorationFrames[i], flipped)) |
| 363 return decorations[i]; | 390 return decorations[i]; |
| 364 } | 391 } |
| 365 | 392 |
| 366 return NULL; | 393 return NULL; |
| 367 } | 394 } |
| 368 | 395 |
| 369 - (NSMenu*)decorationMenuForEvent:(NSEvent*)theEvent | 396 - (NSMenu*)decorationMenuForEvent:(NSEvent*)theEvent |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 [controlView setNeedsDisplay:YES]; | 528 [controlView setNeedsDisplay:YES]; |
| 502 } | 529 } |
| 503 } | 530 } |
| 504 | 531 |
| 505 - (void)setUpTrackingAreasInRect:(NSRect)frame | 532 - (void)setUpTrackingAreasInRect:(NSRect)frame |
| 506 ofView:(AutocompleteTextField*)view { | 533 ofView:(AutocompleteTextField*)view { |
| 507 std::vector<LocationBarDecoration*> decorations; | 534 std::vector<LocationBarDecoration*> decorations; |
| 508 std::vector<NSRect> decorationFrames; | 535 std::vector<NSRect> decorationFrames; |
| 509 NSRect textFrame; | 536 NSRect textFrame; |
| 510 NSRect cellRect = [self clickableFrameForFrame:[view bounds]]; | 537 NSRect cellRect = [self clickableFrameForFrame:[view bounds]]; |
| 511 CalculatePositionsInFrame(cellRect, leftDecorations_, rightDecorations_, | 538 CalculatePositionsInFrame(cellRect, [self textWidth], leftDecorations_, |
| 512 [self edgeWidth], &decorations, &decorationFrames, | 539 rightDecorations_, [self edgeWidth], &decorations, |
| 513 &textFrame); | 540 &decorationFrames, &textFrame); |
| 514 | 541 |
| 515 // Remove previously-registered tracking areas, since we'll update them below. | 542 // Remove previously-registered tracking areas, since we'll update them below. |
| 516 for (CrTrackingArea* area in [view trackingAreas]) { | 543 for (CrTrackingArea* area in [view trackingAreas]) { |
| 517 if ([[area userInfo] objectForKey:kButtonDecorationKey]) | 544 if ([[area userInfo] objectForKey:kButtonDecorationKey]) |
| 518 [view removeTrackingArea:area]; | 545 [view removeTrackingArea:area]; |
| 519 } | 546 } |
| 520 | 547 |
| 521 // Setup new tracking areas for the buttons. | 548 // Setup new tracking areas for the buttons. |
| 522 for (size_t i = 0; i < decorations.size(); ++i) { | 549 for (size_t i = 0; i < decorations.size(); ++i) { |
| 523 ButtonDecoration* button = decorations[i]->AsButtonDecoration(); | 550 ButtonDecoration* button = decorations[i]->AsButtonDecoration(); |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 718 | 745 |
| 719 - (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)isLocal { | 746 - (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)isLocal { |
| 720 return NSDragOperationCopy; | 747 return NSDragOperationCopy; |
| 721 } | 748 } |
| 722 | 749 |
| 723 - (void)updateToolTipsInRect:(NSRect)cellFrame | 750 - (void)updateToolTipsInRect:(NSRect)cellFrame |
| 724 ofView:(AutocompleteTextField*)controlView { | 751 ofView:(AutocompleteTextField*)controlView { |
| 725 std::vector<LocationBarDecoration*> decorations; | 752 std::vector<LocationBarDecoration*> decorations; |
| 726 std::vector<NSRect> decorationFrames; | 753 std::vector<NSRect> decorationFrames; |
| 727 NSRect textFrame; | 754 NSRect textFrame; |
| 728 CalculatePositionsInFrame(cellFrame, leftDecorations_, rightDecorations_, | 755 CalculatePositionsInFrame(cellFrame, [self textWidth], leftDecorations_, |
| 729 [self edgeWidth], &decorations, &decorationFrames, | 756 rightDecorations_, [self edgeWidth], &decorations, |
| 730 &textFrame); | 757 &decorationFrames, &textFrame); |
| 731 | 758 |
| 732 for (size_t i = 0; i < decorations.size(); ++i) { | 759 for (size_t i = 0; i < decorations.size(); ++i) { |
| 733 NSString* tooltip = decorations[i]->GetToolTip(); | 760 NSString* tooltip = decorations[i]->GetToolTip(); |
| 734 if ([tooltip length] > 0) | 761 if ([tooltip length] > 0) |
| 735 [controlView addToolTip:tooltip forRect:decorationFrames[i]]; | 762 [controlView addToolTip:tooltip forRect:decorationFrames[i]]; |
| 736 } | 763 } |
| 737 } | 764 } |
| 738 | 765 |
| 739 - (BOOL)hideFocusState { | 766 - (BOOL)hideFocusState { |
| 740 return hideFocusState_; | 767 return hideFocusState_; |
| 741 } | 768 } |
| 742 | 769 |
| 743 - (void)setHideFocusState:(BOOL)hideFocusState | 770 - (void)setHideFocusState:(BOOL)hideFocusState |
| 744 ofView:(AutocompleteTextField*)controlView { | 771 ofView:(AutocompleteTextField*)controlView { |
| 745 if (hideFocusState_ == hideFocusState) | 772 if (hideFocusState_ == hideFocusState) |
| 746 return; | 773 return; |
| 747 hideFocusState_ = hideFocusState; | 774 hideFocusState_ = hideFocusState; |
| 748 [controlView setNeedsDisplay:YES]; | 775 [controlView setNeedsDisplay:YES]; |
| 749 NSTextView* fieldEditor = | 776 NSTextView* fieldEditor = |
| 750 base::mac::ObjCCastStrict<NSTextView>([controlView currentEditor]); | 777 base::mac::ObjCCastStrict<NSTextView>([controlView currentEditor]); |
| 751 [fieldEditor updateInsertionPointStateAndRestartTimer:YES]; | 778 [fieldEditor updateInsertionPointStateAndRestartTimer:YES]; |
| 752 } | 779 } |
| 753 | 780 |
| 754 - (BOOL)showsFirstResponder { | 781 - (BOOL)showsFirstResponder { |
| 755 return [super showsFirstResponder] && !hideFocusState_; | 782 return [super showsFirstResponder] && !hideFocusState_; |
| 756 } | 783 } |
| 757 | 784 |
| 785 - (CGFloat)textWidth { |
| 786 return [[self attributedStringValue] size].width; |
| 787 } |
| 788 |
| 758 @end | 789 @end |
| OLD | NEW |