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

Side by Side Diff: chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.mm

Issue 2478673002: [Mac] Hover/Pressed background for the Omnibox decorations (Closed)
Patch Set: nit Created 4 years, 1 month 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 unified diff | Download patch
OLDNEW
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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/mac/foundation_util.h" 10 #include "base/mac/foundation_util.h"
11 #include "base/mac/mac_logging.h" 11 #include "base/mac/mac_logging.h"
12 #include "chrome/browser/search/search.h" 12 #include "chrome/browser/search/search.h"
13 #include "chrome/browser/themes/theme_service.h" 13 #include "chrome/browser/themes/theme_service.h"
14 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h" 14 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h"
15 #import "chrome/browser/ui/cocoa/location_bar/location_bar_decoration.h" 15 #import "chrome/browser/ui/cocoa/location_bar/location_bar_decoration.h"
16 #import "chrome/browser/ui/cocoa/themed_window.h" 16 #import "chrome/browser/ui/cocoa/themed_window.h"
17 #include "chrome/grit/theme_resources.h" 17 #include "chrome/grit/theme_resources.h"
18 #import "extensions/common/feature_switch.h" 18 #import "extensions/common/feature_switch.h"
19 #import "third_party/mozilla/NSPasteboard+Utils.h" 19 #import "third_party/mozilla/NSPasteboard+Utils.h"
20 #import "ui/base/cocoa/appkit_utils.h" 20 #import "ui/base/cocoa/appkit_utils.h"
21 #import "ui/base/cocoa/tracking_area.h"
21 #import "ui/base/cocoa/nsview_additions.h" 22 #import "ui/base/cocoa/nsview_additions.h"
22 #include "ui/base/cocoa/scoped_cg_context_smooth_fonts.h" 23 #include "ui/base/cocoa/scoped_cg_context_smooth_fonts.h"
23 #include "ui/base/material_design/material_design_controller.h" 24 #include "ui/base/material_design/material_design_controller.h"
24 25
25 using extensions::FeatureSwitch; 26 using extensions::FeatureSwitch;
26 27
27 namespace { 28 namespace {
28 29
29 // Matches the clipping radius of |GradientButtonCell|. 30 // Matches the clipping radius of |GradientButtonCell|.
30 const CGFloat kCornerRadius = 3.0; 31 const CGFloat kCornerRadius = 3.0;
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 } 176 }
176 177
177 - (BOOL)shouldDrawBezel { 178 - (BOOL)shouldDrawBezel {
178 return YES; 179 return YES;
179 } 180 }
180 181
181 - (CGFloat)lineHeight { 182 - (CGFloat)lineHeight {
182 return 17; 183 return 17;
183 } 184 }
184 185
186 - (void)clearTrackingArea {
187 for (auto& decoration : mouseTrackingDecorations_)
188 decoration->RemoveTrackingArea();
189
190 mouseTrackingDecorations_.clear();
191 }
192
185 - (void)clearDecorations { 193 - (void)clearDecorations {
186 leftDecorations_.clear(); 194 leftDecorations_.clear();
187 rightDecorations_.clear(); 195 rightDecorations_.clear();
196 [self clearTrackingArea];
188 } 197 }
189 198
190 - (void)addLeftDecoration:(LocationBarDecoration*)decoration { 199 - (void)addLeftDecoration:(LocationBarDecoration*)decoration {
191 leftDecorations_.push_back(decoration); 200 leftDecorations_.push_back(decoration);
192 } 201 }
193 202
194 - (void)addRightDecoration:(LocationBarDecoration*)decoration { 203 - (void)addRightDecoration:(LocationBarDecoration*)decoration {
195 rightDecorations_.push_back(decoration); 204 rightDecorations_.push_back(decoration);
196 } 205 }
197 206
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 // If not, discard focus event. 460 // If not, discard focus event.
452 base::scoped_nsobject<NSEvent> focusEvent(focusEvent_.release()); 461 base::scoped_nsobject<NSEvent> focusEvent(focusEvent_.release());
453 if (![theEvent isEqual:focusEvent]) 462 if (![theEvent isEqual:focusEvent])
454 focusEvent.reset(); 463 focusEvent.reset();
455 464
456 LocationBarDecoration* decoration = 465 LocationBarDecoration* decoration =
457 [self decorationForEvent:theEvent inRect:cellFrame ofView:controlView]; 466 [self decorationForEvent:theEvent inRect:cellFrame ofView:controlView];
458 if (!decoration || !decoration->AcceptsMousePress()) 467 if (!decoration || !decoration->AcceptsMousePress())
459 return NO; 468 return NO;
460 469
470 decoration->OnMouseDown();
471
461 NSRect decorationRect = 472 NSRect decorationRect =
462 [self frameForDecoration:decoration inFrame:cellFrame]; 473 [self frameForDecoration:decoration inFrame:cellFrame];
463 474
464 // If the decoration is draggable, then initiate a drag if the user 475 // If the decoration is draggable, then initiate a drag if the user
465 // drags or holds the mouse down for awhile. 476 // drags or holds the mouse down for awhile.
466 if (decoration->IsDraggable()) { 477 if (decoration->IsDraggable()) {
467 NSDate* timeout = 478 NSDate* timeout =
468 [NSDate dateWithTimeIntervalSinceNow:kLocationIconDragTimeout]; 479 [NSDate dateWithTimeIntervalSinceNow:kLocationIconDragTimeout];
469 NSEvent* event = [NSApp nextEventMatchingMask:(NSLeftMouseDraggedMask | 480 NSEvent* event = [NSApp nextEventMatchingMask:(NSLeftMouseDraggedMask |
470 NSLeftMouseUpMask) 481 NSLeftMouseUpMask)
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 DCHECK_EQ([event type], NSLeftMouseUp); 521 DCHECK_EQ([event type], NSLeftMouseUp);
511 } 522 }
512 523
513 const NSPoint mouseLocation = [theEvent locationInWindow]; 524 const NSPoint mouseLocation = [theEvent locationInWindow];
514 const NSPoint point = [controlView convertPoint:mouseLocation fromView:nil]; 525 const NSPoint point = [controlView convertPoint:mouseLocation fromView:nil];
515 return decoration->OnMousePressed( 526 return decoration->OnMousePressed(
516 decorationRect, NSMakePoint(point.x - decorationRect.origin.x, 527 decorationRect, NSMakePoint(point.x - decorationRect.origin.x,
517 point.y - decorationRect.origin.y)); 528 point.y - decorationRect.origin.y));
518 } 529 }
519 530
531 - (void)mouseUp:(NSEvent*)theEvent
532 inRect:(NSRect)cellFrame
533 ofView:(AutocompleteTextField*)controlView {
534 LocationBarDecoration* decoration =
535 [self decorationForEvent:theEvent inRect:cellFrame ofView:controlView];
536 if (decoration)
537 decoration->OnMouseUp();
538 }
539
520 // Returns the file path for file |name| if saved at NSURL |base|. 540 // Returns the file path for file |name| if saved at NSURL |base|.
521 static NSString* PathWithBaseURLAndName(NSURL* base, NSString* name) { 541 static NSString* PathWithBaseURLAndName(NSURL* base, NSString* name) {
522 NSString* filteredName = 542 NSString* filteredName =
523 [name stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 543 [name stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
524 return [[NSURL URLWithString:filteredName relativeToURL:base] path]; 544 return [[NSURL URLWithString:filteredName relativeToURL:base] path];
525 } 545 }
526 546
527 // Returns if there is already a file |name| at dir NSURL |base|. 547 // Returns if there is already a file |name| at dir NSURL |base|.
528 static BOOL FileAlreadyExists(NSURL* base, NSString* name) { 548 static BOOL FileAlreadyExists(NSURL* base, NSString* name) {
529 NSString* path = PathWithBaseURLAndName(base, name); 549 NSString* path = PathWithBaseURLAndName(base, name);
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 ofItemAtPath:[outputURL path] 636 ofItemAtPath:[outputURL path]
617 error:nil]; 637 error:nil];
618 638
619 return [NSArray arrayWithObject:nameWithExtensionStr]; 639 return [NSArray arrayWithObject:nameWithExtensionStr];
620 } 640 }
621 641
622 - (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)isLocal { 642 - (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)isLocal {
623 return NSDragOperationCopy; 643 return NSDragOperationCopy;
624 } 644 }
625 645
626 - (void)updateToolTipsInRect:(NSRect)cellFrame 646 - (void)updateMouseTrackingAndToolTipsInRect:(NSRect)cellFrame
627 ofView:(AutocompleteTextField*)controlView { 647 ofView:
648 (AutocompleteTextField*)controlView {
628 std::vector<LocationBarDecoration*> decorations; 649 std::vector<LocationBarDecoration*> decorations;
629 std::vector<NSRect> decorationFrames; 650 std::vector<NSRect> decorationFrames;
630 NSRect textFrame; 651 NSRect textFrame;
631 CalculatePositionsInFrame(cellFrame, leftDecorations_, rightDecorations_, 652 CalculatePositionsInFrame(cellFrame, leftDecorations_, rightDecorations_,
632 &decorations, &decorationFrames, &textFrame); 653 &decorations, &decorationFrames, &textFrame);
654 [self clearTrackingArea];
633 655
634 for (size_t i = 0; i < decorations.size(); ++i) { 656 for (size_t i = 0; i < decorations.size(); ++i) {
657 CrTrackingArea* trackingArea =
658 decorations[i]->SetupTrackingArea(decorationFrames[i], controlView);
659 if (trackingArea)
660 mouseTrackingDecorations_.push_back(decorations[i]);
661
635 NSString* tooltip = decorations[i]->GetToolTip(); 662 NSString* tooltip = decorations[i]->GetToolTip();
636 if ([tooltip length] > 0) 663 if ([tooltip length] > 0)
637 [controlView addToolTip:tooltip forRect:decorationFrames[i]]; 664 [controlView addToolTip:tooltip forRect:decorationFrames[i]];
638 } 665 }
639 } 666 }
640 667
641 - (BOOL)hideFocusState { 668 - (BOOL)hideFocusState {
642 return hideFocusState_; 669 return hideFocusState_;
643 } 670 }
644 671
(...skipping 14 matching lines...) Expand all
659 686
660 - (void)handleFocusEvent:(NSEvent*)event 687 - (void)handleFocusEvent:(NSEvent*)event
661 ofView:(AutocompleteTextField*)controlView { 688 ofView:(AutocompleteTextField*)controlView {
662 if ([controlView observer]) { 689 if ([controlView observer]) {
663 const bool controlDown = ([event modifierFlags] & NSControlKeyMask) != 0; 690 const bool controlDown = ([event modifierFlags] & NSControlKeyMask) != 0;
664 [controlView observer]->OnSetFocus(controlDown); 691 [controlView observer]->OnSetFocus(controlDown);
665 } 692 }
666 } 693 }
667 694
668 @end 695 @end
696
697 @implementation AutocompleteTextFieldCell (TestingAPI)
698
699 - (const std::vector<LocationBarDecoration*>&)mouseTrackingDecorations {
700 return mouseTrackingDecorations_;
701 }
702
703 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698