Chromium Code Reviews| 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" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 42 } | 42 } |
| 43 | 43 |
| 44 void LocationBarBubbleDelegateView::WebContentMouseHandler::OnTouchEvent( | 44 void LocationBarBubbleDelegateView::WebContentMouseHandler::OnTouchEvent( |
| 45 ui::TouchEvent* event) { | 45 ui::TouchEvent* event) { |
| 46 if (event->type() == ui::ET_TOUCH_PRESSED) | 46 if (event->type() == ui::ET_TOUCH_PRESSED) |
| 47 bubble_->CloseBubble(); | 47 bubble_->CloseBubble(); |
| 48 } | 48 } |
| 49 | 49 |
| 50 LocationBarBubbleDelegateView::LocationBarBubbleDelegateView( | 50 LocationBarBubbleDelegateView::LocationBarBubbleDelegateView( |
| 51 views::View* anchor_view, | 51 views::View* anchor_view, |
| 52 const gfx::Point& anchor_point, | |
| 53 views::BubbleBorder::Arrow arrow, | |
| 54 content::WebContents* web_contents) | |
| 55 : BubbleDialogDelegateView( | |
| 56 anchor_view, | |
| 57 anchor_view ? views::BubbleBorder::TOP_RIGHT : arrow) { | |
| 58 SetupAnchor(anchor_view, anchor_point, arrow, web_contents); | |
| 59 } | |
| 60 | |
| 61 LocationBarBubbleDelegateView::LocationBarBubbleDelegateView( | |
| 62 views::View* anchor_view, | |
| 52 content::WebContents* web_contents) | 63 content::WebContents* web_contents) |
| 53 : BubbleDialogDelegateView(anchor_view, | 64 : BubbleDialogDelegateView(anchor_view, |
|
tapted
2017/04/12 05:08:42
Can the overload just delegate to the other constr
varkha
2017/04/12 09:16:43
Done.
| |
| 54 anchor_view ? views::BubbleBorder::TOP_RIGHT | 65 anchor_view ? views::BubbleBorder::TOP_RIGHT |
| 55 : views::BubbleBorder::NONE) { | 66 : views::BubbleBorder::NONE) { |
| 56 // Add observer to close the bubble if the fullscreen state changes. | 67 SetupAnchor(anchor_view, gfx::Point(), views::BubbleBorder::NONE, |
| 57 if (web_contents) { | 68 web_contents); |
| 58 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); | |
| 59 registrar_.Add( | |
| 60 this, chrome::NOTIFICATION_FULLSCREEN_CHANGED, | |
| 61 content::Source<FullscreenController>( | |
| 62 browser->exclusive_access_manager()->fullscreen_controller())); | |
| 63 } | |
| 64 // Compensate for built-in vertical padding in the anchor view's image. | |
| 65 // In the case of Harmony, this is just compensating for the location bar's | |
| 66 // border thickness, as the bubble's top border should overlap it. | |
| 67 set_anchor_view_insets(gfx::Insets( | |
| 68 GetLayoutConstant(LOCATION_BAR_BUBBLE_ANCHOR_VERTICAL_INSET), 0)); | |
| 69 } | 69 } |
| 70 | 70 |
| 71 LocationBarBubbleDelegateView::~LocationBarBubbleDelegateView() {} | 71 LocationBarBubbleDelegateView::~LocationBarBubbleDelegateView() {} |
| 72 | 72 |
| 73 void LocationBarBubbleDelegateView::ShowForReason(DisplayReason reason) { | 73 void LocationBarBubbleDelegateView::ShowForReason(DisplayReason reason) { |
| 74 if (reason == USER_GESTURE) { | 74 if (reason == USER_GESTURE) { |
| 75 // In the USER_GESTURE case, the icon will be in an active state so the | 75 // In the USER_GESTURE case, the icon will be in an active state so the |
| 76 // bubble doesn't need an arrow. | 76 // bubble doesn't need an arrow. |
| 77 SetArrowPaintType(views::BubbleBorder::PAINT_TRANSPARENT); | 77 SetArrowPaintType(views::BubbleBorder::PAINT_TRANSPARENT); |
| 78 GetWidget()->Show(); | 78 GetWidget()->Show(); |
| 79 } else { | 79 } else { |
| 80 GetWidget()->ShowInactive(); | 80 GetWidget()->ShowInactive(); |
| 81 } | 81 } |
| 82 } | 82 } |
| 83 | 83 |
| 84 int LocationBarBubbleDelegateView::GetDialogButtons() const { | 84 int LocationBarBubbleDelegateView::GetDialogButtons() const { |
| 85 return ui::DIALOG_BUTTON_NONE; | 85 return ui::DIALOG_BUTTON_NONE; |
| 86 } | 86 } |
| 87 | 87 |
| 88 void LocationBarBubbleDelegateView::Observe( | 88 void LocationBarBubbleDelegateView::Observe( |
| 89 int type, | 89 int type, |
| 90 const content::NotificationSource& source, | 90 const content::NotificationSource& source, |
| 91 const content::NotificationDetails& details) { | 91 const content::NotificationDetails& details) { |
| 92 DCHECK_EQ(chrome::NOTIFICATION_FULLSCREEN_CHANGED, type); | 92 DCHECK_EQ(chrome::NOTIFICATION_FULLSCREEN_CHANGED, type); |
| 93 GetWidget()->SetVisibilityAnimationTransition(views::Widget::ANIMATE_NONE); | 93 GetWidget()->SetVisibilityAnimationTransition(views::Widget::ANIMATE_NONE); |
| 94 CloseBubble(); | 94 CloseBubble(); |
| 95 } | 95 } |
| 96 | 96 |
| 97 void LocationBarBubbleDelegateView::SetupAnchor( | |
| 98 views::View* anchor_view, | |
| 99 const gfx::Point& anchor_point, | |
| 100 views::BubbleBorder::Arrow arrow, | |
| 101 content::WebContents* web_contents) { | |
| 102 // Add observer to close the bubble if the fullscreen state changes. | |
| 103 if (web_contents) { | |
| 104 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); | |
| 105 registrar_.Add( | |
| 106 this, chrome::NOTIFICATION_FULLSCREEN_CHANGED, | |
| 107 content::Source<FullscreenController>( | |
| 108 browser->exclusive_access_manager()->fullscreen_controller())); | |
| 109 } | |
| 110 if (!anchor_view) { | |
| 111 SetAnchorRect(gfx::Rect(anchor_point, gfx::Size())); | |
| 112 return; | |
| 113 } | |
| 114 | |
| 115 // Compensate for built-in vertical padding in the anchor view's image. | |
| 116 // In the case of Harmony, this is just compensating for the location bar's | |
| 117 // border thickness, as the bubble's top border should overlap it. | |
| 118 set_anchor_view_insets(gfx::Insets( | |
| 119 GetLayoutConstant(LOCATION_BAR_BUBBLE_ANCHOR_VERTICAL_INSET), 0)); | |
| 120 } | |
| 121 | |
| 97 void LocationBarBubbleDelegateView::CloseBubble() { | 122 void LocationBarBubbleDelegateView::CloseBubble() { |
| 98 GetWidget()->Close(); | 123 GetWidget()->Close(); |
| 99 } | 124 } |
| 100 | 125 |
| 101 void LocationBarBubbleDelegateView::AdjustForFullscreen( | 126 void LocationBarBubbleDelegateView::AdjustForFullscreen( |
| 102 const gfx::Rect& screen_bounds) { | 127 const gfx::Rect& screen_bounds) { |
| 103 if (GetAnchorView()) | 128 if (GetAnchorView()) |
| 104 return; | 129 return; |
| 105 | 130 |
| 106 const int kBubblePaddingFromScreenEdge = 20; | 131 const int kBubblePaddingFromScreenEdge = 20; |
| 107 int horizontal_offset = width() / 2 + kBubblePaddingFromScreenEdge; | 132 int horizontal_offset = width() / 2 + kBubblePaddingFromScreenEdge; |
| 108 const int x_pos = base::i18n::IsRTL() | 133 const int x_pos = base::i18n::IsRTL() |
| 109 ? (screen_bounds.x() + horizontal_offset) | 134 ? (screen_bounds.x() + horizontal_offset) |
| 110 : (screen_bounds.right() - horizontal_offset); | 135 : (screen_bounds.right() - horizontal_offset); |
| 111 SetAnchorRect(gfx::Rect(x_pos, screen_bounds.y(), 0, 0)); | 136 SetAnchorRect(gfx::Rect(x_pos, screen_bounds.y(), 0, 0)); |
| 112 } | 137 } |
| OLD | NEW |