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 29 matching lines...) Expand all Loading... | |
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->window()->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, web_contents, auto_close, |
67 web_contents, | 69 browser_view); |
68 auto_close, | |
69 browser->fullscreen_controller()); | |
70 | 70 |
71 // If we're fullscreen, there is no anchor view, so parent the bubble to | 71 // If we do not have an anchor view, parent the bubble to the content area. |
72 // the content area. | 72 if (!anchor_to_view) { |
73 if (is_fullscreen) { | |
74 zoom_bubble_->set_parent_window( | 73 zoom_bubble_->set_parent_window( |
75 web_contents->GetView()->GetTopLevelNativeWindow()); | 74 web_contents->GetView()->GetTopLevelNativeWindow()); |
76 } | 75 } |
77 | 76 |
78 views::BubbleDelegateView::CreateBubble(zoom_bubble_); | 77 views::BubbleDelegateView::CreateBubble(zoom_bubble_); |
79 | 78 |
80 // Adjust for fullscreen after creation as it relies on the content size. | 79 // Adjust for fullscreen after creation as it relies on the content size. |
81 if (is_fullscreen) | 80 if (is_fullscreen) |
82 zoom_bubble_->AdjustForFullscreen(browser_view->GetBoundsInScreen()); | 81 zoom_bubble_->AdjustForFullscreen(browser_view->GetBoundsInScreen()); |
83 | 82 |
84 zoom_bubble_->GetWidget()->Show(); | 83 zoom_bubble_->GetWidget()->Show(); |
85 } | 84 } |
86 } | 85 } |
87 | 86 |
88 // static | 87 // static |
89 void ZoomBubbleView::CloseBubble() { | 88 void ZoomBubbleView::CloseBubble() { |
90 if (zoom_bubble_) | 89 if (zoom_bubble_) |
91 zoom_bubble_->Close(); | 90 zoom_bubble_->Close(); |
92 } | 91 } |
93 | 92 |
94 // static | 93 // static |
95 bool ZoomBubbleView::IsShowing() { | 94 bool ZoomBubbleView::IsShowing() { |
96 return zoom_bubble_ != NULL; | 95 return zoom_bubble_ != NULL; |
97 } | 96 } |
98 | 97 |
99 ZoomBubbleView::ZoomBubbleView(views::View* anchor_view, | 98 ZoomBubbleView::ZoomBubbleView(views::View* anchor_view, |
100 content::WebContents* web_contents, | 99 content::WebContents* web_contents, |
101 bool auto_close, | 100 bool auto_close, |
102 FullscreenController* fullscreen_controller) | 101 BrowserView* browser_view) |
James Cook
2013/06/17 16:13:41
Can you just pass in immersive mode controller (an
| |
103 : BubbleDelegateView(anchor_view, anchor_view ? | 102 : BubbleDelegateView(anchor_view, anchor_view ? |
104 views::BubbleBorder::TOP_RIGHT : views::BubbleBorder::NONE), | 103 views::BubbleBorder::TOP_RIGHT : views::BubbleBorder::NONE), |
105 label_(NULL), | 104 label_(NULL), |
106 web_contents_(web_contents), | 105 web_contents_(web_contents), |
107 auto_close_(auto_close) { | 106 auto_close_(auto_close) { |
108 // Compensate for built-in vertical padding in the anchor view's image. | 107 // Compensate for built-in vertical padding in the anchor view's image. |
109 set_anchor_view_insets(gfx::Insets(5, 0, 5, 0)); | 108 set_anchor_view_insets(gfx::Insets(5, 0, 5, 0)); |
110 set_use_focusless(auto_close); | 109 set_use_focusless(auto_close); |
111 set_notify_enter_exit_on_child(true); | 110 set_notify_enter_exit_on_child(true); |
112 | 111 |
112 ImmersiveModeController* immersive_controller = | |
113 browser_view->immersive_mode_controller(); | |
114 if (anchor_view) { | |
115 // If we are in immersive fullscreen and the top-of-window views are | |
116 // already revealed, lock the top-of-window views in the revealed state | |
117 // as long as the zoom bubble is visible. ImmersiveModeController does | |
118 // not do this for us automatically because the zoom bubble is not | |
119 // activatable. | |
120 immersive_reveal_lock_.reset(immersive_controller->GetRevealedLock( | |
121 ImmersiveModeController::ANIMATE_REVEAL_NO)); | |
122 } | |
123 | |
124 // Add observers to close the bubble if the fullscreen state or immersive | |
125 // fullscreen revealed state changes. | |
113 registrar_.Add(this, | 126 registrar_.Add(this, |
114 chrome::NOTIFICATION_FULLSCREEN_CHANGED, | 127 chrome::NOTIFICATION_FULLSCREEN_CHANGED, |
115 content::Source<FullscreenController>(fullscreen_controller)); | 128 content::Source<FullscreenController>( |
129 browser_view->browser()->fullscreen_controller())); | |
130 immersive_controller->AddObserver(this); | |
116 } | 131 } |
117 | 132 |
118 ZoomBubbleView::~ZoomBubbleView() { | 133 ZoomBubbleView::~ZoomBubbleView() { |
134 Browser* browser = chrome::FindBrowserWithWebContents(web_contents_); | |
135 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser); | |
136 browser_view->immersive_mode_controller()->RemoveObserver(this); | |
119 } | 137 } |
120 | 138 |
121 void ZoomBubbleView::AdjustForFullscreen(const gfx::Rect& screen_bounds) { | 139 void ZoomBubbleView::AdjustForFullscreen(const gfx::Rect& screen_bounds) { |
122 DCHECK(!anchor_view()); | 140 if (anchor_view()) |
141 return; | |
123 | 142 |
124 // TODO(dbeam): should RTL logic be done in views::BubbleDelegateView? | 143 // TODO(dbeam): should RTL logic be done in views::BubbleDelegateView? |
125 const size_t bubble_half_width = width() / 2; | 144 const size_t bubble_half_width = width() / 2; |
126 const int x_pos = base::i18n::IsRTL() ? | 145 const int x_pos = base::i18n::IsRTL() ? |
127 screen_bounds.x() + bubble_half_width + kFullscreenPaddingEnd : | 146 screen_bounds.x() + bubble_half_width + kFullscreenPaddingEnd : |
128 screen_bounds.right() - bubble_half_width - kFullscreenPaddingEnd; | 147 screen_bounds.right() - bubble_half_width - kFullscreenPaddingEnd; |
129 set_anchor_rect(gfx::Rect(x_pos, screen_bounds.y(), 0, 0)); | 148 set_anchor_rect(gfx::Rect(x_pos, screen_bounds.y(), 0, 0)); |
130 | 149 |
131 // Used to update |views::BubbleDelegate::anchor_rect_| in a semi-hacky way. | 150 // 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. | 151 // 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(); | 230 StartTimerIfNecessary(); |
212 } | 231 } |
213 | 232 |
214 void ZoomBubbleView::Observe(int type, | 233 void ZoomBubbleView::Observe(int type, |
215 const content::NotificationSource& source, | 234 const content::NotificationSource& source, |
216 const content::NotificationDetails& details) { | 235 const content::NotificationDetails& details) { |
217 DCHECK_EQ(type, chrome::NOTIFICATION_FULLSCREEN_CHANGED); | 236 DCHECK_EQ(type, chrome::NOTIFICATION_FULLSCREEN_CHANGED); |
218 CloseBubble(); | 237 CloseBubble(); |
219 } | 238 } |
220 | 239 |
240 void ZoomBubbleView::OnStartedImmersiveReveal() { | |
241 CloseBubble(); | |
242 } | |
243 | |
221 void ZoomBubbleView::WindowClosing() { | 244 void ZoomBubbleView::WindowClosing() { |
222 // |zoom_bubble_| can be a new bubble by this point (as Close(); doesn't | 245 // |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. | 246 // call this right away). Only set to NULL when it's this bubble. |
224 if (zoom_bubble_ == this) | 247 if (zoom_bubble_ == this) |
225 zoom_bubble_ = NULL; | 248 zoom_bubble_ = NULL; |
226 } | 249 } |
OLD | NEW |