Chromium Code Reviews| 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 35aded4deb17a31eaccb49243bcf916fcff7edaf..eea92593e7076b20ab315af9a5aea667ad5bfa5d 100644 |
| --- a/chrome/browser/ui/cocoa/location_bar/zoom_decoration.mm |
| +++ b/chrome/browser/ui/cocoa/location_bar/zoom_decoration.mm |
| @@ -9,6 +9,8 @@ |
| #include "base/strings/string_number_conversions.h" |
| #include "chrome/app/chrome_command_ids.h" |
| #include "chrome/app/vector_icons/vector_icons.h" |
| +#include "chrome/browser/ui/browser_dialogs.h" |
| +#import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| #import "chrome/browser/ui/cocoa/l10n_util.h" |
| #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h" |
| #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.h" |
| @@ -19,11 +21,17 @@ |
| #include "components/zoom/zoom_controller.h" |
| #include "ui/base/cocoa/cocoa_base_utils.h" |
| #include "ui/base/l10n/l10n_util_mac.h" |
| +#include "ui/base/material_design/material_design_controller.h" |
| +#import "ui/gfx/mac/coordinate_conversion.h" |
| ZoomDecoration::ZoomDecoration(LocationBarViewMac* owner) |
| : owner_(owner), bubble_(nullptr), vector_icon_(nullptr) {} |
| ZoomDecoration::~ZoomDecoration() { |
| + if (ui::MaterialDesignController::IsSecondaryUiMaterial()) { |
| + CloseBubble(); |
| + return; |
| + } |
| [bubble_ closeWithoutAnimation]; |
| bubble_.delegate = nil; |
| } |
| @@ -32,7 +40,7 @@ bool ZoomDecoration::UpdateIfNecessary(zoom::ZoomController* zoom_controller, |
| bool default_zoom_changed, |
| bool location_bar_is_dark) { |
| if (!ShouldShowDecoration()) { |
| - if (!IsVisible() && !bubble_) |
| + if (!IsVisible() && !IsBubbleShown()) |
| return false; |
| HideUI(); |
| @@ -77,6 +85,22 @@ void ZoomDecoration::ShowBubble(BOOL auto_close) { |
| const NSRect frame = |
| [[field cell] frameForDecoration:this inFrame:[field bounds]]; |
| + if (ui::MaterialDesignController::IsSecondaryUiMaterial()) { |
| + NSWindow* window = [web_contents->GetNativeView() window]; |
| + if (!window) { |
| + // The tab isn't active right now. |
| + return; |
| + } |
| + BrowserWindowController* bwc = |
|
msw
2017/04/24 18:53:38
nit: avoid acronym identifiers.
varkha
2017/04/26 04:52:59
Done.
|
| + [BrowserWindowController browserWindowControllerForWindow:window]; |
| + NSPoint anchor = [bwc bookmarkBubblePoint]; |
|
msw
2017/04/24 18:53:38
Why show this at the bookmark bubble point? Don't
varkha
2017/04/26 04:52:59
My guess is that this is called bookmark bubble po
|
| + gfx::Point anchor_point = gfx::ScreenPointFromNSPoint( |
| + ui::ConvertPointFromWindowToScreen(window, anchor)); |
| + chrome::ShowZoomBubbleViewsAtPoint(web_contents, anchor_point, |
| + auto_close == NO /* user_action */); |
| + return; |
| + } |
| + |
| // Find point for bubble's arrow in screen coordinates. |
| NSPoint anchor = GetBubblePointInFrame(frame); |
| anchor = [field convertPoint:anchor toView:nil]; |
| @@ -88,11 +112,15 @@ void ZoomDecoration::ShowBubble(BOOL auto_close) { |
| } |
| void ZoomDecoration::CloseBubble() { |
| + if (ui::MaterialDesignController::IsSecondaryUiMaterial()) { |
| + chrome::CloseZoomBubbleViews(); |
| + return; |
| + } |
| [bubble_ close]; |
| } |
| void ZoomDecoration::HideUI() { |
| - [bubble_ close]; |
| + CloseBubble(); |
| SetVisible(false); |
| } |
| @@ -113,7 +141,10 @@ void ZoomDecoration::UpdateUI(zoom::ZoomController* zoom_controller, |
| tooltip_.reset([tooltip_string retain]); |
| - [bubble_ onZoomChanged]; |
| + if (ui::MaterialDesignController::IsSecondaryUiMaterial()) |
| + chrome::RefreshZoomBubbleViews(); |
| + else |
| + [bubble_ onZoomChanged]; |
| } |
| NSPoint ZoomDecoration::GetBubblePointInFrame(NSRect frame) { |
| @@ -133,10 +164,16 @@ bool ZoomDecoration::IsAtDefaultZoom() const { |
| return zoomController && zoomController->IsAtDefaultZoom(); |
| } |
| +bool ZoomDecoration::IsBubbleShown() const { |
| + return (ui::MaterialDesignController::IsSecondaryUiMaterial() && |
| + chrome::IsZoomBubbleViewsShown()) || |
| + bubble_; |
| +} |
| + |
| bool ZoomDecoration::ShouldShowDecoration() const { |
| return owner_->GetWebContents() != NULL && |
| - !owner_->GetToolbarModel()->input_in_progress() && |
| - (bubble_ || !IsAtDefaultZoom()); |
| + !owner_->GetToolbarModel()->input_in_progress() && |
| + (IsBubbleShown() || !IsAtDefaultZoom()); |
| } |
| bool ZoomDecoration::AcceptsMousePress() { |
| @@ -144,10 +181,12 @@ bool ZoomDecoration::AcceptsMousePress() { |
| } |
| bool ZoomDecoration::OnMousePressed(NSRect frame, NSPoint location) { |
| - if (bubble_) |
| + if (IsBubbleShown()) { |
| CloseBubble(); |
| - else |
| - ShowBubble(YES); |
| + } else { |
| + BOOL auto_close = !ui::MaterialDesignController::IsSecondaryUiMaterial(); |
|
varkha
2017/04/24 12:59:37
Note: prefer this to inlining for being self-docum
msw
2017/04/24 18:53:38
Why would we change the auto-close behavior depend
varkha
2017/04/26 04:52:59
I don't think this should be any different from ot
|
| + ShowBubble(auto_close); |
| + } |
| return true; |
| } |
| @@ -160,8 +199,10 @@ content::WebContents* ZoomDecoration::GetWebContents() { |
| } |
| void ZoomDecoration::OnClose() { |
| - bubble_.delegate = nil; |
| - bubble_ = nil; |
| + if (!ui::MaterialDesignController::IsSecondaryUiMaterial()) { |
| + bubble_.delegate = nil; |
| + bubble_ = nil; |
| + } |
| // If the page is at default zoom then hiding the zoom decoration |
| // was suppressed while the bubble was open. Now that the bubble is |