| 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/gfx/geometry/rect.h" | 12 #include "ui/gfx/geometry/rect.h" |
| 13 | 13 |
| 14 LocationBarBubbleDelegateView::LocationBarBubbleDelegateView( | 14 LocationBarBubbleDelegateView::LocationBarBubbleDelegateView( |
| 15 views::View* anchor_view, | 15 views::View* anchor_view, |
| 16 content::WebContents* web_contents) | 16 content::WebContents* web_contents) |
| 17 : BubbleDelegateView(anchor_view, | 17 : BubbleDialogDelegateView(anchor_view, |
| 18 anchor_view ? views::BubbleBorder::TOP_RIGHT | 18 anchor_view ? views::BubbleBorder::TOP_RIGHT |
| 19 : views::BubbleBorder::NONE) { | 19 : views::BubbleBorder::NONE) { |
| 20 // Add observer to close the bubble if the fullscreen state changes. | 20 // Add observer to close the bubble if the fullscreen state changes. |
| 21 if (web_contents) { | 21 if (web_contents) { |
| 22 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); | 22 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); |
| 23 registrar_.Add( | 23 registrar_.Add( |
| 24 this, chrome::NOTIFICATION_FULLSCREEN_CHANGED, | 24 this, chrome::NOTIFICATION_FULLSCREEN_CHANGED, |
| 25 content::Source<FullscreenController>( | 25 content::Source<FullscreenController>( |
| 26 browser->exclusive_access_manager()->fullscreen_controller())); | 26 browser->exclusive_access_manager()->fullscreen_controller())); |
| 27 } | 27 } |
| 28 } | 28 } |
| 29 | 29 |
| 30 LocationBarBubbleDelegateView::~LocationBarBubbleDelegateView() {} | 30 LocationBarBubbleDelegateView::~LocationBarBubbleDelegateView() {} |
| 31 | 31 |
| 32 void LocationBarBubbleDelegateView::ShowForReason(DisplayReason reason) { | 32 void LocationBarBubbleDelegateView::ShowForReason(DisplayReason reason) { |
| 33 if (reason == USER_GESTURE) { | 33 if (reason == USER_GESTURE) { |
| 34 // TODO(estade): re-enable this when crbug.com/518941 is fixed. | 34 // TODO(estade): re-enable this when crbug.com/518941 is fixed. |
| 35 // SetArrowPaintType(views::BubbleBorder::PAINT_TRANSPARENT); | 35 // SetArrowPaintType(views::BubbleBorder::PAINT_TRANSPARENT); |
| 36 GetWidget()->Show(); | 36 GetWidget()->Show(); |
| 37 } else { | 37 } else { |
| 38 GetWidget()->ShowInactive(); | 38 GetWidget()->ShowInactive(); |
| 39 } | 39 } |
| 40 } | 40 } |
| 41 | 41 |
| 42 int LocationBarBubbleDelegateView::GetDialogButtons() const { |
| 43 return ui::DIALOG_BUTTON_NONE; |
| 44 } |
| 45 |
| 42 void LocationBarBubbleDelegateView::Observe( | 46 void LocationBarBubbleDelegateView::Observe( |
| 43 int type, | 47 int type, |
| 44 const content::NotificationSource& source, | 48 const content::NotificationSource& source, |
| 45 const content::NotificationDetails& details) { | 49 const content::NotificationDetails& details) { |
| 46 DCHECK_EQ(chrome::NOTIFICATION_FULLSCREEN_CHANGED, type); | 50 DCHECK_EQ(chrome::NOTIFICATION_FULLSCREEN_CHANGED, type); |
| 47 GetWidget()->SetVisibilityAnimationTransition(views::Widget::ANIMATE_NONE); | 51 GetWidget()->SetVisibilityAnimationTransition(views::Widget::ANIMATE_NONE); |
| 48 Close(); | 52 CloseBubble(); |
| 49 } | 53 } |
| 50 | 54 |
| 51 void LocationBarBubbleDelegateView::Close() { | 55 void LocationBarBubbleDelegateView::CloseBubble() { |
| 52 views::Widget* widget = GetWidget(); | 56 GetWidget()->Close(); |
| 53 if (!widget->IsClosed()) | |
| 54 widget->Close(); | |
| 55 } | 57 } |
| 56 | 58 |
| 57 void LocationBarBubbleDelegateView::AdjustForFullscreen( | 59 void LocationBarBubbleDelegateView::AdjustForFullscreen( |
| 58 const gfx::Rect& screen_bounds) { | 60 const gfx::Rect& screen_bounds) { |
| 59 if (GetAnchorView()) | 61 if (GetAnchorView()) |
| 60 return; | 62 return; |
| 61 | 63 |
| 62 const int kBubblePaddingFromScreenEdge = 20; | 64 const int kBubblePaddingFromScreenEdge = 20; |
| 63 int horizontal_offset = width() / 2 + kBubblePaddingFromScreenEdge; | 65 int horizontal_offset = width() / 2 + kBubblePaddingFromScreenEdge; |
| 64 const int x_pos = base::i18n::IsRTL() | 66 const int x_pos = base::i18n::IsRTL() |
| 65 ? (screen_bounds.x() + horizontal_offset) | 67 ? (screen_bounds.x() + horizontal_offset) |
| 66 : (screen_bounds.right() - horizontal_offset); | 68 : (screen_bounds.right() - horizontal_offset); |
| 67 SetAnchorRect(gfx::Rect(x_pos, screen_bounds.y(), 0, 0)); | 69 SetAnchorRect(gfx::Rect(x_pos, screen_bounds.y(), 0, 0)); |
| 68 } | 70 } |
| OLD | NEW |