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

Unified Diff: chrome/browser/ui/cocoa/location_bar/zoom_decoration.mm

Issue 12286006: [Mac] Implement the basic zoom bubble. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Auto-close bubble Created 7 years, 10 months 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
« no previous file with comments | « chrome/browser/ui/cocoa/location_bar/zoom_decoration.h ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/cocoa/location_bar/zoom_decoration.mm
diff --git a/chrome/browser/ui/cocoa/location_bar/zoom_decoration.mm b/chrome/browser/ui/cocoa/location_bar/zoom_decoration.mm
index f0b3539e0abf592abdeb919802e353b7e2e8a45d..1a5e6e05b44d285c8c3d1062d4d72be572144c58 100644
--- a/chrome/browser/ui/cocoa/location_bar/zoom_decoration.mm
+++ b/chrome/browser/ui/cocoa/location_bar/zoom_decoration.mm
@@ -7,14 +7,18 @@
#include "base/string16.h"
#include "base/strings/string_number_conversions.h"
#include "chrome/app/chrome_command_ids.h"
+#import "chrome/browser/ui/cocoa/browser/zoom_bubble_controller.h"
+#import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h"
+#import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.h"
+#import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h"
#import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h"
-#include "chrome/browser/ui/toolbar/toolbar_model.h"
#include "chrome/browser/ui/zoom/zoom_controller.h"
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util_mac.h"
-ZoomDecoration::ZoomDecoration(ToolbarModel* toolbar_model)
- : toolbar_model_(toolbar_model) {
+ZoomDecoration::ZoomDecoration(LocationBarViewMac* owner)
+ : owner_(owner),
+ bubble_(nil) {
Update(NULL);
}
@@ -22,9 +26,8 @@ ZoomDecoration::~ZoomDecoration() {
}
void ZoomDecoration::Update(ZoomController* zoom_controller) {
- if (!zoom_controller || zoom_controller->IsAtDefaultZoom() ||
- toolbar_model_->GetInputInProgress()) {
- // TODO(dbeam): hide zoom bubble when it exists.
+ if (!zoom_controller || zoom_controller->IsAtDefaultZoom()) {
+ [bubble_ close];
SetVisible(false);
return;
}
@@ -38,12 +41,58 @@ void ZoomDecoration::Update(ZoomController* zoom_controller) {
tooltip_.reset([zoom_string retain]);
SetVisible(true);
+
+ [bubble_ onZoomChanged];
+}
+
+void ZoomDecoration::ShowBubble(BOOL auto_close) {
+ content::WebContents* web_contents = owner_->GetWebContents();
+ if (!web_contents)
+ return;
+
+ // Get the frame of the decoration.
+ AutocompleteTextField* field = owner_->GetAutocompleteTextField();
+ AutocompleteTextFieldCell* cell = [field cell];
+ const NSRect frame = [cell frameForDecoration:this
+ inFrame:[field bounds]];
+
+ // Find point for bubble's arrow in screen coordinates.
+ NSPoint anchor = GetBubblePointInFrame(frame);
+ anchor = [field convertPoint:anchor toView:nil];
+ anchor = [[field window] convertBaseToScreen:anchor];
+
+ if (!bubble_) {
+ void(^observer)(ZoomBubbleController*) = ^(ZoomBubbleController*) {
+ bubble_ = nil;
+ };
+ bubble_ =
+ [[ZoomBubbleController alloc] initWithParentWindow:[field window]
+ closeObserver:observer];
+ }
+
+ [bubble_ showForWebContents:web_contents
+ anchoredAt:anchor
+ autoClose:auto_close];
+}
+
+NSPoint ZoomDecoration::GetBubblePointInFrame(NSRect frame) {
+ NSSize image_size = [GetImage() size];
+ frame.origin.x += frame.size.width - image_size.width;
+ frame.size = image_size;
+
+ const NSRect draw_frame = GetDrawRectInFrame(frame);
+ return NSMakePoint(NSMidX(draw_frame), NSMaxY(draw_frame));
}
bool ZoomDecoration::AcceptsMousePress() {
return true;
}
+bool ZoomDecoration::OnMousePressed(NSRect frame) {
+ ShowBubble(NO);
+ return true;
+}
+
NSString* ZoomDecoration::GetToolTip() {
return tooltip_.get();
}
« no previous file with comments | « chrome/browser/ui/cocoa/location_bar/zoom_decoration.h ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698