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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.mm
diff --git a/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.mm b/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.mm
index 814d89631291ac5102badb244f9f68363a89db1c..1a70f222639746c6ba5292f6d66ef47db6a05eaa 100644
--- a/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.mm
+++ b/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.mm
@@ -18,6 +18,7 @@
#import "extensions/common/feature_switch.h"
#import "third_party/mozilla/NSPasteboard+Utils.h"
#import "ui/base/cocoa/appkit_utils.h"
+#import "ui/base/cocoa/tracking_area.h"
#import "ui/base/cocoa/nsview_additions.h"
#include "ui/base/cocoa/scoped_cg_context_smooth_fonts.h"
#include "ui/base/material_design/material_design_controller.h"
@@ -182,9 +183,17 @@ size_t CalculatePositionsInFrame(
return 17;
}
+- (void)clearTrackingArea {
+ for (auto& decoration : mouseTrackingDecorations_)
+ decoration->RemoveTrackingArea();
+
+ mouseTrackingDecorations_.clear();
+}
+
- (void)clearDecorations {
leftDecorations_.clear();
rightDecorations_.clear();
+ [self clearTrackingArea];
}
- (void)addLeftDecoration:(LocationBarDecoration*)decoration {
@@ -458,6 +467,8 @@ size_t CalculatePositionsInFrame(
if (!decoration || !decoration->AcceptsMousePress())
return NO;
+ decoration->OnMouseDown();
+
NSRect decorationRect =
[self frameForDecoration:decoration inFrame:cellFrame];
@@ -517,6 +528,15 @@ size_t CalculatePositionsInFrame(
point.y - decorationRect.origin.y));
}
+- (void)mouseUp:(NSEvent*)theEvent
+ inRect:(NSRect)cellFrame
+ ofView:(AutocompleteTextField*)controlView {
+ LocationBarDecoration* decoration =
+ [self decorationForEvent:theEvent inRect:cellFrame ofView:controlView];
+ if (decoration)
+ decoration->OnMouseUp();
+}
+
// Returns the file path for file |name| if saved at NSURL |base|.
static NSString* PathWithBaseURLAndName(NSURL* base, NSString* name) {
NSString* filteredName =
@@ -623,15 +643,22 @@ static NSString* UnusedLegalNameForNewDropFile(NSURL* saveLocation,
return NSDragOperationCopy;
}
-- (void)updateToolTipsInRect:(NSRect)cellFrame
- ofView:(AutocompleteTextField*)controlView {
+- (void)updateMouseTrackingAndToolTipsInRect:(NSRect)cellFrame
+ ofView:
+ (AutocompleteTextField*)controlView {
std::vector<LocationBarDecoration*> decorations;
std::vector<NSRect> decorationFrames;
NSRect textFrame;
CalculatePositionsInFrame(cellFrame, leftDecorations_, rightDecorations_,
&decorations, &decorationFrames, &textFrame);
+ [self clearTrackingArea];
for (size_t i = 0; i < decorations.size(); ++i) {
+ CrTrackingArea* trackingArea =
+ decorations[i]->SetupTrackingArea(decorationFrames[i], controlView);
+ if (trackingArea)
+ mouseTrackingDecorations_.push_back(decorations[i]);
+
NSString* tooltip = decorations[i]->GetToolTip();
if ([tooltip length] > 0)
[controlView addToolTip:tooltip forRect:decorationFrames[i]];
@@ -666,3 +693,11 @@ static NSString* UnusedLegalNameForNewDropFile(NSURL* saveLocation,
}
@end
+
+@implementation AutocompleteTextFieldCell (TestingAPI)
+
+- (const std::vector<LocationBarDecoration*>&)mouseTrackingDecorations {
+ return mouseTrackingDecorations_;
+}
+
+@end

Powered by Google App Engine
This is Rietveld 408576698