| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "chrome/browser/ui/views/location_bar/location_bar_bubble_delegate_view
.h" | 5 #include "chrome/browser/ui/views/location_bar/location_bar_bubble_delegate_view
.h" |
| 6 | 6 |
| 7 #include "chrome/browser/chrome_notification_types.h" | 7 #include "chrome/browser/chrome_notification_types.h" |
| 8 #include "chrome/browser/ui/browser.h" | 8 #include "chrome/browser/ui/browser.h" |
| 9 #include "chrome/browser/ui/browser_finder.h" | 9 #include "chrome/browser/ui/browser_finder.h" |
| 10 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h" | 10 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h" |
| 11 #include "content/public/browser/notification_source.h" | 11 #include "content/public/browser/notification_source.h" |
| 12 #include "ui/base/material_design/material_design_controller.h" | 12 #include "ui/base/material_design/material_design_controller.h" |
| 13 #include "ui/gfx/geometry/rect.h" | 13 #include "ui/gfx/geometry/rect.h" |
| 14 | 14 |
| 15 LocationBarBubbleDelegateView::LocationBarBubbleDelegateView( | 15 LocationBarBubbleDelegateView::LocationBarBubbleDelegateView( |
| 16 views::View* anchor_view, | 16 views::View* anchor_view, |
| 17 content::WebContents* web_contents) | 17 content::WebContents* web_contents) |
| 18 : BubbleDelegateView(anchor_view, | 18 : BubbleDialogDelegateView(anchor_view, |
| 19 anchor_view ? views::BubbleBorder::TOP_RIGHT | 19 anchor_view ? views::BubbleBorder::TOP_RIGHT |
| 20 : views::BubbleBorder::NONE) { | 20 : views::BubbleBorder::NONE) { |
| 21 // Add observer to close the bubble if the fullscreen state changes. | 21 // Add observer to close the bubble if the fullscreen state changes. |
| 22 if (web_contents) { | 22 if (web_contents) { |
| 23 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); | 23 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); |
| 24 registrar_.Add( | 24 registrar_.Add( |
| 25 this, chrome::NOTIFICATION_FULLSCREEN_CHANGED, | 25 this, chrome::NOTIFICATION_FULLSCREEN_CHANGED, |
| 26 content::Source<FullscreenController>( | 26 content::Source<FullscreenController>( |
| 27 browser->exclusive_access_manager()->fullscreen_controller())); | 27 browser->exclusive_access_manager()->fullscreen_controller())); |
| 28 } | 28 } |
| 29 } | 29 } |
| 30 | 30 |
| 31 LocationBarBubbleDelegateView::~LocationBarBubbleDelegateView() {} | 31 LocationBarBubbleDelegateView::~LocationBarBubbleDelegateView() {} |
| 32 | 32 |
| 33 void LocationBarBubbleDelegateView::ShowForReason(DisplayReason reason) { | 33 void LocationBarBubbleDelegateView::ShowForReason(DisplayReason reason) { |
| 34 if (reason == USER_GESTURE) { | 34 if (reason == USER_GESTURE) { |
| 35 // In the USER_GESTURE case, the icon will be in an active state so the | 35 // In the USER_GESTURE case, the icon will be in an active state so the |
| 36 // bubble doesn't need an arrow. | 36 // bubble doesn't need an arrow. |
| 37 if (ui::MaterialDesignController::IsModeMaterial()) | 37 if (ui::MaterialDesignController::IsModeMaterial()) |
| 38 SetArrowPaintType(views::BubbleBorder::PAINT_TRANSPARENT); | 38 SetArrowPaintType(views::BubbleBorder::PAINT_TRANSPARENT); |
| 39 GetWidget()->Show(); | 39 GetWidget()->Show(); |
| 40 } else { | 40 } else { |
| 41 GetWidget()->ShowInactive(); | 41 GetWidget()->ShowInactive(); |
| 42 } | 42 } |
| 43 } | 43 } |
| 44 | 44 |
| 45 int LocationBarBubbleDelegateView::GetDialogButtons() const { |
| 46 return ui::DIALOG_BUTTON_NONE; |
| 47 } |
| 48 |
| 45 void LocationBarBubbleDelegateView::Observe( | 49 void LocationBarBubbleDelegateView::Observe( |
| 46 int type, | 50 int type, |
| 47 const content::NotificationSource& source, | 51 const content::NotificationSource& source, |
| 48 const content::NotificationDetails& details) { | 52 const content::NotificationDetails& details) { |
| 49 DCHECK_EQ(chrome::NOTIFICATION_FULLSCREEN_CHANGED, type); | 53 DCHECK_EQ(chrome::NOTIFICATION_FULLSCREEN_CHANGED, type); |
| 50 GetWidget()->SetVisibilityAnimationTransition(views::Widget::ANIMATE_NONE); | 54 GetWidget()->SetVisibilityAnimationTransition(views::Widget::ANIMATE_NONE); |
| 51 Close(); | 55 CloseBubble(); |
| 52 } | 56 } |
| 53 | 57 |
| 54 void LocationBarBubbleDelegateView::Close() { | 58 void LocationBarBubbleDelegateView::CloseBubble() { |
| 55 views::Widget* widget = GetWidget(); | 59 GetWidget()->Close(); |
| 56 if (!widget->IsClosed()) | |
| 57 widget->Close(); | |
| 58 } | 60 } |
| 59 | 61 |
| 60 void LocationBarBubbleDelegateView::AdjustForFullscreen( | 62 void LocationBarBubbleDelegateView::AdjustForFullscreen( |
| 61 const gfx::Rect& screen_bounds) { | 63 const gfx::Rect& screen_bounds) { |
| 62 if (GetAnchorView()) | 64 if (GetAnchorView()) |
| 63 return; | 65 return; |
| 64 | 66 |
| 65 const int kBubblePaddingFromScreenEdge = 20; | 67 const int kBubblePaddingFromScreenEdge = 20; |
| 66 int horizontal_offset = width() / 2 + kBubblePaddingFromScreenEdge; | 68 int horizontal_offset = width() / 2 + kBubblePaddingFromScreenEdge; |
| 67 const int x_pos = base::i18n::IsRTL() | 69 const int x_pos = base::i18n::IsRTL() |
| 68 ? (screen_bounds.x() + horizontal_offset) | 70 ? (screen_bounds.x() + horizontal_offset) |
| 69 : (screen_bounds.right() - horizontal_offset); | 71 : (screen_bounds.right() - horizontal_offset); |
| 70 SetAnchorRect(gfx::Rect(x_pos, screen_bounds.y(), 0, 0)); | 72 SetAnchorRect(gfx::Rect(x_pos, screen_bounds.y(), 0, 0)); |
| 71 } | 73 } |
| OLD | NEW |