| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/cocoa/location_bar/autocomplete_text_field_cell.h" | 5 #import "chrome/browser/cocoa/location_bar/autocomplete_text_field_cell.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #import "chrome/browser/cocoa/image_utils.h" | 8 #import "chrome/browser/cocoa/image_utils.h" |
| 9 #import "chrome/browser/cocoa/location_bar/location_bar_decoration.h" | 9 #import "chrome/browser/cocoa/location_bar/location_bar_decoration.h" |
| 10 | 10 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 | 21 |
| 22 @end | 22 @end |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 const CGFloat kBaselineAdjust = 2.0; | 26 const CGFloat kBaselineAdjust = 2.0; |
| 27 | 27 |
| 28 // Matches the clipping radius of |GradientButtonCell|. | 28 // Matches the clipping radius of |GradientButtonCell|. |
| 29 const CGFloat kCornerRadius = 4.0; | 29 const CGFloat kCornerRadius = 4.0; |
| 30 | 30 |
| 31 // Gap to leave between hint and right-hand-side of cell. | |
| 32 const NSInteger kHintXOffset = 4; | |
| 33 | |
| 34 // How far to shift bounding box of hint down from top of field. | 31 // How far to shift bounding box of hint down from top of field. |
| 35 // Assumes -setFlipped:YES. | 32 // Assumes -setFlipped:YES. |
| 36 const NSInteger kHintYOffset = 4; | 33 const NSInteger kHintYOffset = 4; |
| 37 | 34 |
| 38 // TODO(shess): The keyword hint image wants to sit on the baseline. | 35 // TODO(shess): The keyword hint image wants to sit on the baseline. |
| 39 // This moves it down so that there is approximately as much image | 36 // This moves it down so that there is approximately as much image |
| 40 // above the lowercase ascender as below the baseline. A better | 37 // above the lowercase ascender as below the baseline. A better |
| 41 // technique would be nice to have, though. | 38 // technique would be nice to have, though. |
| 42 const NSInteger kKeywordHintImageBaseline = -6; | 39 const NSInteger kKeywordHintImageBaseline = -6; |
| 43 | 40 |
| 44 // How far to shift bounding box of hint icon label down from top of field. | 41 // How far to shift bounding box of hint icon label down from top of field. |
| 45 const NSInteger kIconLabelYOffset = 7; | 42 const NSInteger kIconLabelYOffset = 7; |
| 46 | 43 |
| 47 // How far the editor insets itself, for purposes of determining if | 44 // How far the editor insets itself, for purposes of determining if |
| 48 // decorations need to be trimmed. | 45 // decorations need to be trimmed. |
| 49 const CGFloat kEditorHorizontalInset = 3.0; | 46 const CGFloat kEditorHorizontalInset = 3.0; |
| 50 | 47 |
| 51 // How far to inset the left-hand decorations from the field's bounds. | 48 // How far to inset the left-hand decorations from the field's bounds. |
| 52 const CGFloat kLeftDecorationXOffset = 3.0; | 49 const CGFloat kLeftDecorationXOffset = 3.0; |
| 53 | 50 |
| 51 // How far to inset the right-hand decorations from the field's bounds. |
| 52 // TODO(shess): Why is this different from |kLeftDecorationXOffset|? |
| 53 const CGFloat kRightDecorationXOffset = 4.0; |
| 54 |
| 54 // The amount of padding on either side reserved for drawing decorations. | 55 // The amount of padding on either side reserved for drawing decorations. |
| 55 const NSInteger kDecorationHorizontalPad = 3; | 56 const CGFloat kDecorationHorizontalPad = 3; |
| 56 | 57 |
| 57 // How long to wait for mouse-up on the location icon before assuming | 58 // How long to wait for mouse-up on the location icon before assuming |
| 58 // that the user wants to drag. | 59 // that the user wants to drag. |
| 59 const NSTimeInterval kLocationIconDragTimeout = 0.25; | 60 const NSTimeInterval kLocationIconDragTimeout = 0.25; |
| 60 | 61 |
| 61 // Conveniences to centralize width+offset calculations. | 62 // Conveniences to centralize width+offset calculations. |
| 62 CGFloat WidthForHint(NSAttributedString* hintString) { | 63 CGFloat WidthForHint(NSAttributedString* hintString) { |
| 63 return kHintXOffset + ceil([hintString size].width); | 64 return kRightDecorationXOffset + ceil([hintString size].width); |
| 64 } | 65 } |
| 65 | 66 |
| 66 // Convenience to draw |image| in the |rect| portion of |view|. | 67 // Convenience to draw |image| in the |rect| portion of |view|. |
| 67 void DrawImageInRect(NSImage* image, NSView* view, const NSRect& rect) { | 68 void DrawImageInRect(NSImage* image, NSView* view, const NSRect& rect) { |
| 68 // If there is an image, make sure we calculated the target size | 69 // If there is an image, make sure we calculated the target size |
| 69 // correctly. | 70 // correctly. |
| 70 DCHECK(!image || NSEqualSizes([image size], rect.size)); | 71 DCHECK(!image || NSEqualSizes([image size], rect.size)); |
| 71 [image drawInRect:rect | 72 [image drawInRect:rect |
| 72 fromRect:NSZeroRect // Entire image | 73 fromRect:NSZeroRect // Entire image |
| 73 operation:NSCompositeSourceOver | 74 operation:NSCompositeSourceOver |
| (...skipping 16 matching lines...) Expand all Loading... |
| 90 scoped_nsobject<NSMutableAttributedString> as( | 91 scoped_nsobject<NSMutableAttributedString> as( |
| 91 [[NSAttributedString attributedStringWithAttachment:attachment] | 92 [[NSAttributedString attributedStringWithAttachment:attachment] |
| 92 mutableCopy]); | 93 mutableCopy]); |
| 93 [as addAttribute:NSBaselineOffsetAttributeName | 94 [as addAttribute:NSBaselineOffsetAttributeName |
| 94 value:[NSNumber numberWithFloat:baselineAdjustment] | 95 value:[NSNumber numberWithFloat:baselineAdjustment] |
| 95 range:NSMakeRange(0, [as length])]; | 96 range:NSMakeRange(0, [as length])]; |
| 96 | 97 |
| 97 return [[as copy] autorelease]; | 98 return [[as copy] autorelease]; |
| 98 } | 99 } |
| 99 | 100 |
| 100 // Helper function for calculating placement of decorations w/in the | 101 // Calculate the positions for a set of decorations. |frame| is the |
| 101 // cell. |frame| is the cell's boundary rectangle. | 102 // overall frame to do layout in, |remaining_frame| will get the |
| 102 // |left_decorations| is a set of decorations for the left-hand side | 103 // left-over space. |all_decorations| is the set of decorations to |
| 103 // of the cell, before the text. |decorations| will contain the | 104 // lay out, |decorations| will be set to the decorations which are |
| 104 // resulting visible decorations, and |decoration_frames| will contain | 105 // visible and which fit, in the same order as |all_decorations|, |
| 105 // their frames in the same coordinates as |frame|. |remaining_frame| | 106 // while |decoration_frames| will be the corresponding frames. |
| 106 // will contain the frame left over for the field editor. | 107 // |x_edge| describes the edge to layout the decorations against |
| 107 void CalculatePositionsInFrame( | 108 // (|NSMinXEdge| or |NSMaxXEdge|). |initial_padding| is the padding |
| 108 const NSRect cell_frame, | 109 // from the edge of |cell_frame| (|kDecorationHorizontalPad| is used |
| 109 const std::vector<LocationBarDecoration*>& left_decorations, | 110 // between decorations). |
| 111 void CalculatePositionsHelper( |
| 112 NSRect frame, |
| 113 const std::vector<LocationBarDecoration*>& all_decorations, |
| 114 NSRectEdge x_edge, |
| 115 CGFloat initial_padding, |
| 110 std::vector<LocationBarDecoration*>* decorations, | 116 std::vector<LocationBarDecoration*>* decorations, |
| 111 std::vector<NSRect>* decoration_frames, | 117 std::vector<NSRect>* decoration_frames, |
| 112 NSRect* remaining_frame) { | 118 NSRect* remaining_frame) { |
| 113 NSRect frame = cell_frame; | 119 DCHECK(x_edge == NSMinXEdge || x_edge == NSMaxXEdge); |
| 120 DCHECK_EQ(decorations->size(), decoration_frames->size()); |
| 114 | 121 |
| 115 // The left-most decoration will be inset a bit further from the edge. | 122 // The outer-most decoration will be inset a bit further from the |
| 116 CGFloat left_padding = kLeftDecorationXOffset; | 123 // edge. |
| 124 CGFloat padding = initial_padding; |
| 117 | 125 |
| 118 decorations->clear(); | 126 for (size_t i = 0; i < all_decorations.size(); ++i) { |
| 119 decoration_frames->clear(); | 127 if (all_decorations[i]->IsVisible()) { |
| 128 NSRect padding_rect, available; |
| 120 | 129 |
| 121 for (size_t i = 0; i < left_decorations.size(); ++i) { | 130 // Peel off the outside padding. |
| 122 if (left_decorations[i]->IsVisible()) { | 131 NSDivideRect(frame, &padding_rect, &available, padding, x_edge); |
| 123 NSRect padding, available; | |
| 124 | |
| 125 // Peel off the left-side padding. | |
| 126 NSDivideRect(frame, &padding, &available, left_padding, NSMinXEdge); | |
| 127 | 132 |
| 128 // Find out how large the decoration will be in the remaining | 133 // Find out how large the decoration will be in the remaining |
| 129 // space. | 134 // space. |
| 130 const CGFloat used_width = | 135 const CGFloat used_width = |
| 131 left_decorations[i]->GetWidthForSpace(NSWidth(available)); | 136 all_decorations[i]->GetWidthForSpace(NSWidth(available)); |
| 132 | 137 |
| 133 if (used_width != LocationBarDecoration::kOmittedWidth) { | 138 if (used_width != LocationBarDecoration::kOmittedWidth) { |
| 134 DCHECK_GT(used_width, 0.0); | 139 DCHECK_GT(used_width, 0.0); |
| 135 NSRect decoration_frame; | 140 NSRect decoration_frame; |
| 136 | 141 |
| 137 // Peel off the desired width, leaving the remainder in | 142 // Peel off the desired width, leaving the remainder in |
| 138 // |frame|. | 143 // |frame|. |
| 139 NSDivideRect(available, &decoration_frame, &frame, | 144 NSDivideRect(available, &decoration_frame, &frame, |
| 140 used_width, NSMinXEdge); | 145 used_width, x_edge); |
| 141 | 146 |
| 142 decorations->push_back(left_decorations[i]); | 147 decorations->push_back(all_decorations[i]); |
| 143 decoration_frames->push_back(decoration_frame); | 148 decoration_frames->push_back(decoration_frame); |
| 144 DCHECK_EQ(decorations->size(), decoration_frames->size()); | 149 DCHECK_EQ(decorations->size(), decoration_frames->size()); |
| 145 | 150 |
| 146 // Adjust padding for between decorations. | 151 // Adjust padding for between decorations. |
| 147 left_padding = kDecorationHorizontalPad; | 152 padding = kDecorationHorizontalPad; |
| 148 } | 153 } |
| 149 } | 154 } |
| 150 } | 155 } |
| 151 | 156 |
| 157 DCHECK_EQ(decorations->size(), decoration_frames->size()); |
| 152 *remaining_frame = frame; | 158 *remaining_frame = frame; |
| 159 } |
| 160 |
| 161 // Helper function for calculating placement of decorations w/in the |
| 162 // cell. |frame| is the cell's boundary rectangle, |remaining_frame| |
| 163 // will get any space left after decorations are laid out (for text). |
| 164 // |left_decorations| is a set of decorations for the left-hand side |
| 165 // of the cell, |right_decorations| for the right-hand side. |
| 166 // |decorations| will contain the resulting visible decorations, and |
| 167 // |decoration_frames| will contain their frames in the same |
| 168 // coordinates as |frame|. Decorations will be ordered left to right. |
| 169 void CalculatePositionsInFrame( |
| 170 NSRect frame, |
| 171 const std::vector<LocationBarDecoration*>& left_decorations, |
| 172 const std::vector<LocationBarDecoration*>& right_decorations, |
| 173 std::vector<LocationBarDecoration*>* decorations, |
| 174 std::vector<NSRect>* decoration_frames, |
| 175 NSRect* remaining_frame) { |
| 176 decorations->clear(); |
| 177 decoration_frames->clear(); |
| 178 |
| 179 // Layout |left_decorations| against the LHS. |
| 180 CalculatePositionsHelper(frame, left_decorations, |
| 181 NSMinXEdge, kLeftDecorationXOffset, |
| 182 decorations, decoration_frames, &frame); |
| 153 DCHECK_EQ(decorations->size(), decoration_frames->size()); | 183 DCHECK_EQ(decorations->size(), decoration_frames->size()); |
| 184 |
| 185 // Capture the number of visible left-hand decorations. |
| 186 const size_t left_count = decorations->size(); |
| 187 |
| 188 // Layout |right_decorations| against the RHS. |
| 189 CalculatePositionsHelper(frame, right_decorations, |
| 190 NSMaxXEdge, kRightDecorationXOffset, |
| 191 decorations, decoration_frames, &frame); |
| 192 DCHECK_EQ(decorations->size(), decoration_frames->size()); |
| 193 |
| 194 // Reverse the right-hand decorations so that overall everything is |
| 195 // sorted left to right. |
| 196 std::reverse(decorations->begin() + left_count, decorations->end()); |
| 197 std::reverse(decoration_frames->begin() + left_count, |
| 198 decoration_frames->end()); |
| 199 |
| 200 *remaining_frame = frame; |
| 154 } | 201 } |
| 155 | 202 |
| 156 } // namespace | 203 } // namespace |
| 157 | 204 |
| 158 @implementation AutocompleteTextAttachmentCell | 205 @implementation AutocompleteTextAttachmentCell |
| 159 | 206 |
| 160 - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)aView { | 207 - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)aView { |
| 161 // Draw image with |DrawImageInRect()| to get consistent | 208 // Draw image with |DrawImageInRect()| to get consistent |
| 162 // flipped treatment. | 209 // flipped treatment. |
| 163 DrawImageInRect([self image], aView, cellFrame); | 210 DrawImageInRect([self image], aView, cellFrame); |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 } | 360 } |
| 314 | 361 |
| 315 - (void)clearHint { | 362 - (void)clearHint { |
| 316 hintString_.reset(); | 363 hintString_.reset(); |
| 317 } | 364 } |
| 318 | 365 |
| 319 - (void)setPageActionViewList:(LocationBarViewMac::PageActionViewList*)list { | 366 - (void)setPageActionViewList:(LocationBarViewMac::PageActionViewList*)list { |
| 320 page_action_views_ = list; | 367 page_action_views_ = list; |
| 321 } | 368 } |
| 322 | 369 |
| 323 - (void)setStarIconView:(LocationBarViewMac::LocationBarImageView*)view { | |
| 324 starIconView_ = view; | |
| 325 } | |
| 326 | |
| 327 - (void)setContentSettingViewsList: | 370 - (void)setContentSettingViewsList: |
| 328 (LocationBarViewMac::ContentSettingViews*)views { | 371 (LocationBarViewMac::ContentSettingViews*)views { |
| 329 content_setting_views_ = views; | 372 content_setting_views_ = views; |
| 330 } | 373 } |
| 331 | 374 |
| 332 - (void)clearDecorations { | 375 - (void)clearDecorations { |
| 333 leftDecorations_.clear(); | 376 leftDecorations_.clear(); |
| 377 rightDecorations_.clear(); |
| 334 } | 378 } |
| 335 | 379 |
| 336 - (void)addLeftDecoration:(LocationBarDecoration*)decoration { | 380 - (void)addLeftDecoration:(LocationBarDecoration*)decoration { |
| 337 leftDecorations_.push_back(decoration); | 381 leftDecorations_.push_back(decoration); |
| 338 } | 382 } |
| 339 | 383 |
| 384 - (void)addRightDecoration:(LocationBarDecoration*)decoration { |
| 385 rightDecorations_.push_back(decoration); |
| 386 } |
| 387 |
| 340 - (CGFloat)availableWidthInFrame:(const NSRect)frame { | 388 - (CGFloat)availableWidthInFrame:(const NSRect)frame { |
| 341 std::vector<LocationBarDecoration*> decorations; | 389 std::vector<LocationBarDecoration*> decorations; |
| 342 std::vector<NSRect> decorationFrames; | 390 std::vector<NSRect> decorationFrames; |
| 343 NSRect textFrame; | 391 NSRect textFrame; |
| 344 CalculatePositionsInFrame(frame, leftDecorations_, | 392 CalculatePositionsInFrame(frame, leftDecorations_, rightDecorations_, |
| 345 &decorations, &decorationFrames, &textFrame); | 393 &decorations, &decorationFrames, &textFrame); |
| 346 | 394 |
| 347 return NSWidth(textFrame); | 395 return NSWidth(textFrame); |
| 348 } | 396 } |
| 349 | 397 |
| 350 - (NSRect)frameForDecoration:(const LocationBarDecoration*)aDecoration | 398 - (NSRect)frameForDecoration:(const LocationBarDecoration*)aDecoration |
| 351 inFrame:(NSRect)cellFrame { | 399 inFrame:(NSRect)cellFrame { |
| 352 // Short-circuit if the decoration is known to be not visible. | 400 // Short-circuit if the decoration is known to be not visible. |
| 353 if (aDecoration && !aDecoration->IsVisible()) | 401 if (aDecoration && !aDecoration->IsVisible()) |
| 354 return NSZeroRect; | 402 return NSZeroRect; |
| 355 | 403 |
| 356 // Layout the decorations. | 404 // Layout the decorations. |
| 357 std::vector<LocationBarDecoration*> decorations; | 405 std::vector<LocationBarDecoration*> decorations; |
| 358 std::vector<NSRect> decorationFrames; | 406 std::vector<NSRect> decorationFrames; |
| 359 NSRect textFrame; | 407 NSRect textFrame; |
| 360 CalculatePositionsInFrame(cellFrame, leftDecorations_, | 408 CalculatePositionsInFrame(cellFrame, leftDecorations_, rightDecorations_, |
| 361 &decorations, &decorationFrames, &textFrame); | 409 &decorations, &decorationFrames, &textFrame); |
| 362 | 410 |
| 363 // Find our decoration and return the corresponding frame. | 411 // Find our decoration and return the corresponding frame. |
| 364 std::vector<LocationBarDecoration*>::const_iterator iter = | 412 std::vector<LocationBarDecoration*>::const_iterator iter = |
| 365 std::find(decorations.begin(), decorations.end(), aDecoration); | 413 std::find(decorations.begin(), decorations.end(), aDecoration); |
| 366 if (iter != decorations.end()) { | 414 if (iter != decorations.end()) { |
| 367 const size_t index = iter - decorations.begin(); | 415 const size_t index = iter - decorations.begin(); |
| 368 return decorationFrames[index]; | 416 return decorationFrames[index]; |
| 369 } | 417 } |
| 370 | 418 |
| 371 // Decorations which are not visible should have been filtered out | 419 // Decorations which are not visible should have been filtered out |
| 372 // at the top, but return |NSZeroRect| rather than a 0-width rect | 420 // at the top, but return |NSZeroRect| rather than a 0-width rect |
| 373 // for consistency. | 421 // for consistency. |
| 374 NOTREACHED(); | 422 NOTREACHED(); |
| 375 return NSZeroRect; | 423 return NSZeroRect; |
| 376 } | 424 } |
| 377 | 425 |
| 378 // Overriden to account for the hint strings and hint icons. | 426 // Overriden to account for the hint strings and hint icons. |
| 379 - (NSRect)textFrameForFrame:(NSRect)cellFrame { | 427 - (NSRect)textFrameForFrame:(NSRect)cellFrame { |
| 380 // Get the frame adjusted for decorations. | 428 // Get the frame adjusted for decorations. |
| 381 std::vector<LocationBarDecoration*> decorations; | 429 std::vector<LocationBarDecoration*> decorations; |
| 382 std::vector<NSRect> decorationFrames; | 430 std::vector<NSRect> decorationFrames; |
| 383 NSRect textFrame = [super textFrameForFrame:cellFrame]; | 431 NSRect textFrame = [super textFrameForFrame:cellFrame]; |
| 384 CalculatePositionsInFrame(textFrame, leftDecorations_, | 432 CalculatePositionsInFrame(textFrame, leftDecorations_, rightDecorations_, |
| 385 &decorations, &decorationFrames, &textFrame); | 433 &decorations, &decorationFrames, &textFrame); |
| 386 | 434 |
| 387 // NOTE: This function must closely match the logic in | 435 // NOTE: This function must closely match the logic in |
| 388 // |-drawInteriorWithFrame:inView:|. | 436 // |-drawInteriorWithFrame:inView:|. |
| 389 | 437 |
| 390 // Leave room for items on the right (SSL label, page actions, etc). | 438 // Leave room for items on the right (SSL label, page actions, etc). |
| 391 // Icons are laid out in |cellFrame| rather than |textFrame| for | 439 // Icons are laid out in |cellFrame| rather than |textFrame| for |
| 392 // consistency with drawing code. | 440 // consistency with drawing code. |
| 393 NSArray* icons = [self layedOutIcons:cellFrame]; | 441 NSArray* icons = [self layedOutIcons:cellFrame]; |
| 394 if ([icons count]) { | 442 if ([icons count]) { |
| 395 // Max x for resulting text frame. | 443 // Max x for resulting text frame. |
| 396 const CGFloat maxX = NSMinX([[icons objectAtIndex:0] rect]); | 444 const CGFloat maxX = NSMinX([[icons objectAtIndex:0] rect]); |
| 397 textFrame.size.width = maxX - NSMinX(textFrame); | 445 textFrame.size.width = maxX - NSMinX(textFrame); |
| 398 } | 446 } |
| 399 | 447 |
| 400 // Keyword string or hint string if they fit. | 448 // Keyword string or hint string if they fit. |
| 401 if (hintString_) { | 449 if (hintString_) { |
| 402 const CGFloat hintWidth(WidthForHint(hintString_)); | 450 const CGFloat hintWidth(WidthForHint(hintString_)); |
| 403 | 451 |
| 404 // TODO(shess): This could be better. Show the hint until the | 452 // TODO(shess): This could be better. Show the hint until the |
| 405 // non-hint text bumps against it? | 453 // non-hint text bumps against it? |
| 406 if (hintWidth < NSWidth(textFrame)) { | 454 if (hintWidth < NSWidth(textFrame)) { |
| 407 textFrame.size.width -= hintWidth; | 455 textFrame.size.width -= hintWidth; |
| 408 } | 456 } |
| 409 } | 457 } |
| 410 | 458 |
| 411 return textFrame; | 459 return textFrame; |
| 412 } | 460 } |
| 413 | 461 |
| 414 - (NSRect)starIconFrameForFrame:(NSRect)cellFrame { | |
| 415 if (!starIconView_ || !starIconView_->IsVisible()) | |
| 416 return NSZeroRect; | |
| 417 | |
| 418 // The star icon is always at the RHS. | |
| 419 scoped_nsobject<AutocompleteTextFieldIcon> icon( | |
| 420 [[AutocompleteTextFieldIcon alloc] initImageWithView:starIconView_]); | |
| 421 cellFrame.size.width -= kHintXOffset; | |
| 422 [icon positionInFrame:cellFrame]; | |
| 423 return [icon rect]; | |
| 424 } | |
| 425 | |
| 426 - (size_t)pageActionCount { | 462 - (size_t)pageActionCount { |
| 427 // page_action_views_ may be NULL during testing, or if the | 463 // page_action_views_ may be NULL during testing, or if the |
| 428 // containing LocationViewMac object has already been destructed | 464 // containing LocationViewMac object has already been destructed |
| 429 // (happens sometimes during window shutdown). | 465 // (happens sometimes during window shutdown). |
| 430 if (!page_action_views_) | 466 if (!page_action_views_) |
| 431 return 0; | 467 return 0; |
| 432 return page_action_views_->Count(); | 468 return page_action_views_->Count(); |
| 433 } | 469 } |
| 434 | 470 |
| 435 - (NSRect)pageActionFrameForIndex:(size_t)index inFrame:(NSRect)cellFrame { | 471 - (NSRect)pageActionFrameForIndex:(size_t)index inFrame:(NSRect)cellFrame { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 cellFrame.origin.y + kHintYOffset, | 505 cellFrame.origin.y + kHintYOffset, |
| 470 ceil([hintString_ size].width), | 506 ceil([hintString_ size].width), |
| 471 cellFrame.size.height - kHintYOffset)); | 507 cellFrame.size.height - kHintYOffset)); |
| 472 [hintString_.get() drawInRect:infoFrame]; | 508 [hintString_.get() drawInRect:infoFrame]; |
| 473 } | 509 } |
| 474 | 510 |
| 475 - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { | 511 - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { |
| 476 std::vector<LocationBarDecoration*> decorations; | 512 std::vector<LocationBarDecoration*> decorations; |
| 477 std::vector<NSRect> decorationFrames; | 513 std::vector<NSRect> decorationFrames; |
| 478 NSRect workingFrame; | 514 NSRect workingFrame; |
| 479 CalculatePositionsInFrame(cellFrame, leftDecorations_, | 515 CalculatePositionsInFrame(cellFrame, leftDecorations_, rightDecorations_, |
| 480 &decorations, &decorationFrames, &workingFrame); | 516 &decorations, &decorationFrames, &workingFrame); |
| 481 | 517 |
| 482 // Draw the decorations first. | 518 // Draw the decorations first. |
| 483 for (size_t i = 0; i < decorations.size(); ++i) { | 519 for (size_t i = 0; i < decorations.size(); ++i) { |
| 484 if (decorations[i]) | 520 if (decorations[i]) |
| 485 decorations[i]->DrawInFrame(decorationFrames[i], controlView); | 521 decorations[i]->DrawInFrame(decorationFrames[i], controlView); |
| 486 } | 522 } |
| 487 | 523 |
| 488 // NOTE: This function must closely match the logic in | 524 // NOTE: This function must closely match the logic in |
| 489 // |-textFrameForFrame:|. | 525 // |-textFrameForFrame:|. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 508 [self drawHintWithFrame:cellFrame inView:controlView]; | 544 [self drawHintWithFrame:cellFrame inView:controlView]; |
| 509 workingFrame.size.width -= hintWidth; | 545 workingFrame.size.width -= hintWidth; |
| 510 } | 546 } |
| 511 } | 547 } |
| 512 | 548 |
| 513 // Superclass draws text portion WRT original |cellFrame|. | 549 // Superclass draws text portion WRT original |cellFrame|. |
| 514 [super drawInteriorWithFrame:cellFrame inView:controlView]; | 550 [super drawInteriorWithFrame:cellFrame inView:controlView]; |
| 515 } | 551 } |
| 516 | 552 |
| 517 - (NSArray*)layedOutIcons:(NSRect)cellFrame { | 553 - (NSArray*)layedOutIcons:(NSRect)cellFrame { |
| 554 // Trim the decoration area from |cellFrame|. This is duplicate |
| 555 // work WRT the caller in some cases, but locating this here is |
| 556 // simpler, and this code will go away soon. |
| 557 std::vector<LocationBarDecoration*> decorations; |
| 558 std::vector<NSRect> decorationFrames; |
| 559 CalculatePositionsInFrame(cellFrame, leftDecorations_, rightDecorations_, |
| 560 &decorations, &decorationFrames, &cellFrame); |
| 561 |
| 518 // The set of views to display right-justified in the cell, from | 562 // The set of views to display right-justified in the cell, from |
| 519 // left to right. | 563 // left to right. |
| 520 NSMutableArray* result = [NSMutableArray array]; | 564 NSMutableArray* result = [NSMutableArray array]; |
| 521 | 565 |
| 522 // Collect the image views for bulk processing. | 566 // Collect the image views for bulk processing. |
| 523 // TODO(shess): Refactor with LocationBarViewMac to make the | 567 // TODO(shess): Refactor with LocationBarViewMac to make the |
| 524 // different types of items more consistent. | 568 // different types of items more consistent. |
| 525 std::vector<LocationBarViewMac::LocationBarImageView*> views; | 569 std::vector<LocationBarViewMac::LocationBarImageView*> views; |
| 526 | 570 |
| 527 if (content_setting_views_) { | 571 if (content_setting_views_) { |
| 528 views.insert(views.end(), | 572 views.insert(views.end(), |
| 529 content_setting_views_->begin(), | 573 content_setting_views_->begin(), |
| 530 content_setting_views_->end()); | 574 content_setting_views_->end()); |
| 531 } | 575 } |
| 532 | 576 |
| 533 // TODO(shess): Previous implementation of this method made a | 577 // TODO(shess): Previous implementation of this method made a |
| 534 // right-to-left array, so add the page-action items in that order. | 578 // right-to-left array, so add the page-action items in that order. |
| 535 // As part of the refactor mentioned above, lay everything out | 579 // As part of the refactor mentioned above, lay everything out |
| 536 // nicely left-to-right. | 580 // nicely left-to-right. |
| 537 for (size_t i = [self pageActionCount]; i-- > 0;) { | 581 for (size_t i = [self pageActionCount]; i-- > 0;) { |
| 538 views.push_back(page_action_views_->ViewAt(i)); | 582 views.push_back(page_action_views_->ViewAt(i)); |
| 539 } | 583 } |
| 540 | 584 |
| 541 // The star icon should always come last. | |
| 542 if (starIconView_) | |
| 543 views.push_back(starIconView_); | |
| 544 | |
| 545 // Load the visible views into |result|. | 585 // Load the visible views into |result|. |
| 546 for (std::vector<LocationBarViewMac::LocationBarImageView*>::const_iterator | 586 for (std::vector<LocationBarViewMac::LocationBarImageView*>::const_iterator |
| 547 iter = views.begin(); iter != views.end(); ++iter) { | 587 iter = views.begin(); iter != views.end(); ++iter) { |
| 548 if ((*iter)->IsVisible()) { | 588 if ((*iter)->IsVisible()) { |
| 549 scoped_nsobject<AutocompleteTextFieldIcon> icon( | 589 scoped_nsobject<AutocompleteTextFieldIcon> icon( |
| 550 [[AutocompleteTextFieldIcon alloc] initImageWithView:*iter]); | 590 [[AutocompleteTextFieldIcon alloc] initImageWithView:*iter]); |
| 551 [result addObject:icon]; | 591 [result addObject:icon]; |
| 552 } | 592 } |
| 553 } | 593 } |
| 554 | 594 |
| 555 // Leave a boundary at RHS of field. | 595 // Padding from right-hand decoration. There should always be at |
| 556 cellFrame.size.width -= kHintXOffset; | 596 // least one (the star). |
| 597 cellFrame.size.width -= kDecorationHorizontalPad; |
| 557 | 598 |
| 558 // Position each view within the frame from right to left. | 599 // Position each view within the frame from right to left. |
| 559 for (AutocompleteTextFieldIcon* icon in [result reverseObjectEnumerator]) { | 600 for (AutocompleteTextFieldIcon* icon in [result reverseObjectEnumerator]) { |
| 560 [icon positionInFrame:cellFrame]; | 601 [icon positionInFrame:cellFrame]; |
| 561 | 602 |
| 562 // Trim the icon's space from the frame. | 603 // Trim the icon's space from the frame. |
| 563 cellFrame.size.width = NSMinX([icon rect]) - kDecorationHorizontalPad; | 604 cellFrame.size.width = |
| 605 NSMinX([icon rect]) - NSMinX(cellFrame) - kDecorationHorizontalPad; |
| 564 } | 606 } |
| 565 return result; | 607 return result; |
| 566 } | 608 } |
| 567 | 609 |
| 568 // Returns the decoration under |theEvent|, or NULL if none. | 610 // Returns the decoration under |theEvent|, or NULL if none. |
| 569 // Like |-iconForEvent:inRect:ofView:|, but for decorations. | 611 // Like |-iconForEvent:inRect:ofView:|, but for decorations. |
| 570 - (LocationBarDecoration*)decorationForEvent:(NSEvent*)theEvent | 612 - (LocationBarDecoration*)decorationForEvent:(NSEvent*)theEvent |
| 571 inRect:(NSRect)cellFrame | 613 inRect:(NSRect)cellFrame |
| 572 ofView:(AutocompleteTextField*)controlView | 614 ofView:(AutocompleteTextField*)controlView |
| 573 { | 615 { |
| 574 const BOOL flipped = [controlView isFlipped]; | 616 const BOOL flipped = [controlView isFlipped]; |
| 575 const NSPoint location = | 617 const NSPoint location = |
| 576 [controlView convertPoint:[theEvent locationInWindow] fromView:nil]; | 618 [controlView convertPoint:[theEvent locationInWindow] fromView:nil]; |
| 577 | 619 |
| 578 std::vector<LocationBarDecoration*> decorations; | 620 std::vector<LocationBarDecoration*> decorations; |
| 579 std::vector<NSRect> decorationFrames; | 621 std::vector<NSRect> decorationFrames; |
| 580 NSRect textFrame; | 622 NSRect textFrame; |
| 581 CalculatePositionsInFrame(cellFrame, leftDecorations_, | 623 CalculatePositionsInFrame(cellFrame, leftDecorations_, rightDecorations_, |
| 582 &decorations, &decorationFrames, &textFrame); | 624 &decorations, &decorationFrames, &textFrame); |
| 583 | 625 |
| 584 for (size_t i = 0; i < decorations.size(); ++i) { | 626 for (size_t i = 0; i < decorations.size(); ++i) { |
| 585 if (NSMouseInRect(location, decorationFrames[i], flipped)) | 627 if (NSMouseInRect(location, decorationFrames[i], flipped)) |
| 586 return decorations[i]; | 628 return decorations[i]; |
| 587 } | 629 } |
| 588 | 630 |
| 589 return NULL; | 631 return NULL; |
| 590 } | 632 } |
| 591 | 633 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 688 } | 730 } |
| 689 | 731 |
| 690 return YES; | 732 return YES; |
| 691 } | 733 } |
| 692 | 734 |
| 693 - (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)isLocal { | 735 - (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)isLocal { |
| 694 return NSDragOperationCopy; | 736 return NSDragOperationCopy; |
| 695 } | 737 } |
| 696 | 738 |
| 697 @end | 739 @end |
| OLD | NEW |