OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/zoom_bubble_view.h" | 5 #include "chrome/browser/ui/views/location_bar/zoom_bubble_view.h" |
6 | 6 |
7 #include "base/i18n/rtl.h" | 7 #include "base/i18n/rtl.h" |
8 #include "chrome/browser/chrome_page_zoom.h" | 8 #include "chrome/browser/chrome_page_zoom.h" |
9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
10 #include "chrome/browser/ui/browser_finder.h" | 10 #include "chrome/browser/ui/browser_finder.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 // static | 39 // static |
40 ZoomBubbleView* ZoomBubbleView::zoom_bubble_ = NULL; | 40 ZoomBubbleView* ZoomBubbleView::zoom_bubble_ = NULL; |
41 | 41 |
42 // static | 42 // static |
43 void ZoomBubbleView::ShowBubble(content::WebContents* web_contents, | 43 void ZoomBubbleView::ShowBubble(content::WebContents* web_contents, |
44 bool auto_close) { | 44 bool auto_close) { |
45 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); | 45 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); |
46 DCHECK(browser && browser->window() && browser->fullscreen_controller()); | 46 DCHECK(browser && browser->window() && browser->fullscreen_controller()); |
47 | 47 |
48 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser); | 48 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser); |
49 bool is_fullscreen = browser->window()->IsFullscreen(); | 49 bool is_fullscreen = browser_view->IsFullscreen(); |
50 views::View* anchor_view = is_fullscreen ? | 50 bool anchor_to_view = !is_fullscreen || |
51 NULL : browser_view->GetLocationBarView()->zoom_view(); | 51 browser_view->immersive_mode_controller()->IsRevealed(); |
| 52 views::View* anchor_view = anchor_to_view ? |
| 53 browser_view->GetLocationBarView()->zoom_view() : NULL; |
52 | 54 |
53 // If the bubble is already showing in this window and its |auto_close_| value | 55 // If the bubble is already showing in this window and its |auto_close_| value |
54 // is equal to |auto_close|, the bubble can be reused and only the label text | 56 // is equal to |auto_close|, the bubble can be reused and only the label text |
55 // needs to be updated. | 57 // needs to be updated. |
56 if (zoom_bubble_ && | 58 if (zoom_bubble_ && |
57 zoom_bubble_->anchor_view() == anchor_view && | 59 zoom_bubble_->anchor_view() == anchor_view && |
58 zoom_bubble_->auto_close_ == auto_close) { | 60 zoom_bubble_->auto_close_ == auto_close) { |
59 zoom_bubble_->Refresh(); | 61 zoom_bubble_->Refresh(); |
60 } else { | 62 } else { |
61 // If the bubble is already showing but its |auto_close_| value is not equal | 63 // If the bubble is already showing but its |auto_close_| value is not equal |
62 // to |auto_close|, the bubble's focus properties must change, so the | 64 // to |auto_close|, the bubble's focus properties must change, so the |
63 // current bubble must be closed and a new one created. | 65 // current bubble must be closed and a new one created. |
64 CloseBubble(); | 66 CloseBubble(); |
65 | 67 |
66 zoom_bubble_ = new ZoomBubbleView(anchor_view, | 68 zoom_bubble_ = new ZoomBubbleView(anchor_view, |
67 web_contents, | 69 web_contents, |
68 auto_close, | 70 auto_close, |
| 71 browser_view->immersive_mode_controller(), |
69 browser->fullscreen_controller()); | 72 browser->fullscreen_controller()); |
70 | 73 |
71 // If we're fullscreen, there is no anchor view, so parent the bubble to | 74 // If we do not have an anchor view, parent the bubble to the content area. |
72 // the content area. | 75 if (!anchor_to_view) { |
73 if (is_fullscreen) { | |
74 zoom_bubble_->set_parent_window( | 76 zoom_bubble_->set_parent_window( |
75 web_contents->GetView()->GetTopLevelNativeWindow()); | 77 web_contents->GetView()->GetTopLevelNativeWindow()); |
76 } | 78 } |
77 | 79 |
78 views::BubbleDelegateView::CreateBubble(zoom_bubble_); | 80 views::BubbleDelegateView::CreateBubble(zoom_bubble_); |
79 | 81 |
80 // Adjust for fullscreen after creation as it relies on the content size. | 82 // Adjust for fullscreen after creation as it relies on the content size. |
81 if (is_fullscreen) | 83 if (is_fullscreen) |
82 zoom_bubble_->AdjustForFullscreen(browser_view->GetBoundsInScreen()); | 84 zoom_bubble_->AdjustForFullscreen(browser_view->GetBoundsInScreen()); |
83 | 85 |
84 zoom_bubble_->GetWidget()->Show(); | 86 zoom_bubble_->GetWidget()->Show(); |
85 } | 87 } |
86 } | 88 } |
87 | 89 |
88 // static | 90 // static |
89 void ZoomBubbleView::CloseBubble() { | 91 void ZoomBubbleView::CloseBubble() { |
90 if (zoom_bubble_) | 92 if (zoom_bubble_) |
91 zoom_bubble_->Close(); | 93 zoom_bubble_->Close(); |
92 } | 94 } |
93 | 95 |
94 // static | 96 // static |
95 bool ZoomBubbleView::IsShowing() { | 97 bool ZoomBubbleView::IsShowing() { |
96 return zoom_bubble_ != NULL; | 98 // The bubble may be in the process of closing. |
| 99 return zoom_bubble_ != NULL && zoom_bubble_->GetWidget()->IsVisible(); |
97 } | 100 } |
98 | 101 |
99 ZoomBubbleView::ZoomBubbleView(views::View* anchor_view, | 102 // static |
100 content::WebContents* web_contents, | 103 const ZoomBubbleView* ZoomBubbleView::GetZoomBubbleForTest() { |
101 bool auto_close, | 104 return zoom_bubble_; |
102 FullscreenController* fullscreen_controller) | 105 } |
| 106 |
| 107 ZoomBubbleView::ZoomBubbleView( |
| 108 views::View* anchor_view, |
| 109 content::WebContents* web_contents, |
| 110 bool auto_close, |
| 111 ImmersiveModeController* immersive_mode_controller, |
| 112 FullscreenController* fullscreen_controller) |
103 : BubbleDelegateView(anchor_view, anchor_view ? | 113 : BubbleDelegateView(anchor_view, anchor_view ? |
104 views::BubbleBorder::TOP_RIGHT : views::BubbleBorder::NONE), | 114 views::BubbleBorder::TOP_RIGHT : views::BubbleBorder::NONE), |
105 label_(NULL), | 115 label_(NULL), |
106 web_contents_(web_contents), | 116 web_contents_(web_contents), |
107 auto_close_(auto_close) { | 117 auto_close_(auto_close), |
| 118 immersive_mode_controller_(immersive_mode_controller) { |
108 // Compensate for built-in vertical padding in the anchor view's image. | 119 // Compensate for built-in vertical padding in the anchor view's image. |
109 set_anchor_view_insets(gfx::Insets(5, 0, 5, 0)); | 120 set_anchor_view_insets(gfx::Insets(5, 0, 5, 0)); |
110 set_use_focusless(auto_close); | 121 set_use_focusless(auto_close); |
111 set_notify_enter_exit_on_child(true); | 122 set_notify_enter_exit_on_child(true); |
112 | 123 |
| 124 if (anchor_view) { |
| 125 // If we are in immersive fullscreen and the top-of-window views are |
| 126 // already revealed, lock the top-of-window views in the revealed state |
| 127 // as long as the zoom bubble is visible. ImmersiveModeController does |
| 128 // not do this for us automatically because the zoom bubble is not |
| 129 // activatable. |
| 130 immersive_reveal_lock_.reset(immersive_mode_controller_->GetRevealedLock( |
| 131 ImmersiveModeController::ANIMATE_REVEAL_NO)); |
| 132 } |
| 133 |
| 134 // Add observers to close the bubble if the fullscreen state or immersive |
| 135 // fullscreen revealed state changes. |
113 registrar_.Add(this, | 136 registrar_.Add(this, |
114 chrome::NOTIFICATION_FULLSCREEN_CHANGED, | 137 chrome::NOTIFICATION_FULLSCREEN_CHANGED, |
115 content::Source<FullscreenController>(fullscreen_controller)); | 138 content::Source<FullscreenController>(fullscreen_controller)); |
| 139 immersive_mode_controller_->AddObserver(this); |
116 } | 140 } |
117 | 141 |
118 ZoomBubbleView::~ZoomBubbleView() { | 142 ZoomBubbleView::~ZoomBubbleView() { |
| 143 if (immersive_mode_controller_) |
| 144 immersive_mode_controller_->RemoveObserver(this); |
119 } | 145 } |
120 | 146 |
121 void ZoomBubbleView::AdjustForFullscreen(const gfx::Rect& screen_bounds) { | 147 void ZoomBubbleView::AdjustForFullscreen(const gfx::Rect& screen_bounds) { |
122 DCHECK(!anchor_view()); | 148 if (anchor_view()) |
| 149 return; |
123 | 150 |
124 // TODO(dbeam): should RTL logic be done in views::BubbleDelegateView? | 151 // TODO(dbeam): should RTL logic be done in views::BubbleDelegateView? |
125 const size_t bubble_half_width = width() / 2; | 152 const size_t bubble_half_width = width() / 2; |
126 const int x_pos = base::i18n::IsRTL() ? | 153 const int x_pos = base::i18n::IsRTL() ? |
127 screen_bounds.x() + bubble_half_width + kFullscreenPaddingEnd : | 154 screen_bounds.x() + bubble_half_width + kFullscreenPaddingEnd : |
128 screen_bounds.right() - bubble_half_width - kFullscreenPaddingEnd; | 155 screen_bounds.right() - bubble_half_width - kFullscreenPaddingEnd; |
129 set_anchor_rect(gfx::Rect(x_pos, screen_bounds.y(), 0, 0)); | 156 set_anchor_rect(gfx::Rect(x_pos, screen_bounds.y(), 0, 0)); |
130 | 157 |
131 // Used to update |views::BubbleDelegate::anchor_rect_| in a semi-hacky way. | 158 // Used to update |views::BubbleDelegate::anchor_rect_| in a semi-hacky way. |
132 // TODO(dbeam): update only the bounds of this view or its border or frame. | 159 // TODO(dbeam): update only the bounds of this view or its border or frame. |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 StartTimerIfNecessary(); | 238 StartTimerIfNecessary(); |
212 } | 239 } |
213 | 240 |
214 void ZoomBubbleView::Observe(int type, | 241 void ZoomBubbleView::Observe(int type, |
215 const content::NotificationSource& source, | 242 const content::NotificationSource& source, |
216 const content::NotificationDetails& details) { | 243 const content::NotificationDetails& details) { |
217 DCHECK_EQ(type, chrome::NOTIFICATION_FULLSCREEN_CHANGED); | 244 DCHECK_EQ(type, chrome::NOTIFICATION_FULLSCREEN_CHANGED); |
218 CloseBubble(); | 245 CloseBubble(); |
219 } | 246 } |
220 | 247 |
| 248 void ZoomBubbleView::OnImmersiveRevealStarted() { |
| 249 CloseBubble(); |
| 250 } |
| 251 |
| 252 void ZoomBubbleView::OnImmersiveModeControllerDestroyed() { |
| 253 immersive_mode_controller_ = NULL; |
| 254 } |
| 255 |
221 void ZoomBubbleView::WindowClosing() { | 256 void ZoomBubbleView::WindowClosing() { |
222 // |zoom_bubble_| can be a new bubble by this point (as Close(); doesn't | 257 // |zoom_bubble_| can be a new bubble by this point (as Close(); doesn't |
223 // call this right away). Only set to NULL when it's this bubble. | 258 // call this right away). Only set to NULL when it's this bubble. |
224 if (zoom_bubble_ == this) | 259 if (zoom_bubble_ == this) |
225 zoom_bubble_ = NULL; | 260 zoom_bubble_ = NULL; |
226 } | 261 } |
OLD | NEW |