Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ui/views/compact_nav/compact_location_bar_view_host.h" | |
| 6 | |
| 7 #include <algorithm> | |
| 8 | |
| 9 #if defined(OS_LINUX) | |
|
sky
2011/05/03 18:38:32
TOOLKIT_USES_GTK
SteveT
2011/05/06 18:48:43
Done.
| |
| 10 #include <gtk/gtk.h> | |
| 11 #endif | |
| 12 | |
| 13 #include "base/i18n/rtl.h" | |
| 14 #include "chrome/browser/browser_process.h" | |
| 15 #include "chrome/browser/platform_util.h" | |
| 16 #include "chrome/browser/ui/browser.h" | |
| 17 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | |
| 18 #include "chrome/browser/ui/view_ids.h" | |
| 19 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h" | |
| 20 #include "chrome/browser/ui/views/compact_nav/compact_location_bar_view.h" | |
| 21 #include "chrome/browser/ui/views/frame/browser_view.h" | |
| 22 #include "chrome/browser/ui/views/tabs/base_tab_strip.h" | |
| 23 #include "content/browser/renderer_host/render_view_host.h" | |
| 24 #include "content/browser/tab_contents/tab_contents.h" | |
| 25 #include "content/browser/tab_contents/tab_contents_view.h" | |
| 26 #include "content/common/notification_source.h" | |
| 27 #include "ui/base/animation/slide_animation.h" | |
| 28 #include "ui/base/keycodes/keyboard_codes.h" | |
| 29 #include "views/controls/scrollbar/native_scroll_bar.h" | |
| 30 #include "views/events/event.h" | |
| 31 #include "views/focus/external_focus_tracker.h" | |
| 32 #include "views/focus/view_storage.h" | |
| 33 #include "views/widget/root_view.h" | |
| 34 #include "views/widget/widget.h" | |
| 35 | |
| 36 const int kHideTimeoutInSeconds = 2; | |
|
sky
2011/05/03 18:38:32
either use static for these variables, or put in a
SteveT
2011/05/06 18:48:43
Done.
| |
| 37 | |
| 38 // TODO(stevet): Share this with CompactLocationBarView. This is the actual | |
| 39 // height, without the overlap added. | |
| 40 const int kCompactNavbarSpacerHeight = 4; | |
| 41 | |
| 42 const int kBookmarkBarLocationBarOverlap = 2; | |
| 43 const int kSpacerLocationbarOverlap = 1; | |
| 44 | |
| 45 #if !defined(OS_MACOSX) // MessageLoopForUI::Observer isn't available on Mac. | |
|
sky
2011/05/03 18:38:32
views doesn't run on osx, so I don't see any point
SteveT
2011/05/06 18:48:43
Removed.
| |
| 46 // An mouse event observer to detect a mouse click on | |
| 47 // BrowserView's content area and hide the location bar. | |
| 48 class MouseObserver : public MessageLoopForUI::Observer { | |
|
sky
2011/05/03 18:38:32
Don't inline all the methods of this class.
SteveT
2011/05/06 18:48:43
Done - Moved definitions out and below.
| |
| 49 public: | |
| 50 MouseObserver(CompactLocationBarViewHost* host, ::BrowserView* view) | |
| 51 : host_(host), | |
| 52 browser_view_(view), | |
| 53 observing_(false) { | |
| 54 top_level_window_ = browser_view_->GetWidget()->GetNativeView(); | |
| 55 } | |
| 56 | |
|
sky
2011/05/03 18:38:32
Destructor should invoke StopObservering.
SteveT
2011/05/06 18:48:43
Done.
| |
| 57 // MessageLoopForUI::Observer overrides. | |
| 58 #if defined(OS_WIN) | |
| 59 virtual void WillProcessMessage(const MSG& native_event) {} | |
|
sky
2011/05/03 18:38:32
OVERRIDE on all these
SteveT
2011/05/06 18:48:43
Done.
| |
| 60 virtual void DidProcessMessage(const MSG& native_event) { | |
| 61 #elif defined(OS_LINUX) | |
| 62 virtual void WillProcessEvent(GdkEvent* native_event) {} | |
| 63 virtual void DidProcessEvent(GdkEvent* native_event) { | |
| 64 #endif | |
| 65 // Hide the location bar iff the mouse is pressed on the | |
| 66 // BrowserView's content area. | |
| 67 if (!IsMouseEvent(native_event)) | |
| 68 return; | |
| 69 views::MouseEvent event(native_event); | |
| 70 if (event.type() == ui::ET_MOUSE_PRESSED && | |
| 71 IsSameTopLevelWindow(native_event) && | |
| 72 HitContentArea(event.x(), event.y())) { | |
| 73 host_->Hide(true); | |
|
sky
2011/05/03 18:38:32
What if the user alt-tabs or the active window cha
SteveT
2011/05/06 18:48:43
In these cases, the drop down will remain in the s
| |
| 74 } | |
| 75 } | |
| 76 | |
| 77 void Observe(MessageLoopForUI* loop) { | |
| 78 if (!observing_) { | |
| 79 loop->AddObserver(this); | |
| 80 observing_ = true; | |
| 81 } | |
| 82 } | |
| 83 | |
| 84 void StopObserving(MessageLoopForUI* loop) { | |
| 85 if (observing_) { | |
| 86 loop->RemoveObserver(this); | |
| 87 observing_ = false; | |
| 88 } | |
| 89 } | |
| 90 | |
| 91 private: | |
| 92 // TODO(mad): would be nice to have this on the views::Event class. | |
| 93 bool IsMouseEvent(views::NativeEvent native_event) { | |
|
sky
2011/05/03 18:38:32
Can this take a const NativeEvent& ?
SteveT
2011/05/06 18:48:43
Sure can!!
| |
| 94 #if defined(OS_WIN) | |
| 95 // Copied from views\events\event_win.cc. | |
| 96 return native_event.message == WM_MOUSELEAVE || | |
| 97 native_event.message == WM_MOUSEHOVER || | |
|
sky
2011/05/03 18:38:32
indentation is off, and refactor so you aren't cop
SteveT
2011/05/06 18:48:43
Fixed. I've fixed the helpers in event_win.cc to t
| |
| 98 (native_event.message >= WM_MOUSEFIRST && | |
| 99 native_event.message <= WM_MOUSELAST) || | |
| 100 native_event.message == WM_NCMOUSELEAVE || | |
| 101 native_event.message == WM_NCMOUSEHOVER || | |
| 102 (native_event.message >= WM_NCMOUSEMOVE && | |
| 103 native_event.message <= WM_NCXBUTTONDBLCLK); | |
| 104 #elif defined(OS_LINUX) | |
| 105 return native_event->type == GDK_MOTION_NOTIFY || | |
| 106 native_event->type == GDK_BUTTON_PRESS || | |
| 107 native_event->type == GDK_2BUTTON_PRESS || | |
| 108 native_event->type == GDK_3BUTTON_PRESS || | |
| 109 native_event->type == GDK_BUTTON_RELEASE; | |
| 110 #endif | |
| 111 } | |
| 112 // TODO(mad): Would be nice to have a NativeEvent -> NativeWindow mapping. | |
|
sky
2011/05/03 18:38:32
newline between 111 and 112. And feel free to add
SteveT
2011/05/06 18:48:43
Haven't figured this mapping out yet... we'll take
| |
| 113 // Then, with a a GetTopLevel receiving a NativeWindow, we could do this | |
| 114 // in a platform independent way. | |
| 115 bool IsSameTopLevelWindow(views::NativeEvent native_event) { | |
| 116 #if defined(OS_WIN) | |
| 117 return platform_util::GetTopLevel(native_event.hwnd) == top_level_window_; | |
| 118 #elif defined(OS_LINUX) | |
| 119 return gdk_window_get_toplevel(((GdkEventAny*)native_event)->window) == | |
|
sky
2011/05/03 18:38:32
Use C++ casts
SteveT
2011/05/06 18:48:43
Done.
| |
| 120 top_level_window_->window; | |
| 121 #endif | |
| 122 } | |
| 123 // Tests if the event occurred on the content area, using | |
|
sky
2011/05/03 18:38:32
newline bewtween 122 and 123.
SteveT
2011/05/06 18:48:43
Done.
| |
| 124 // root window's coordinates. | |
| 125 bool HitContentArea(int x, int y) { | |
| 126 gfx::Point p(x, y); | |
| 127 // First, exclude the location bar as it's shown on top of | |
| 128 // content area. | |
| 129 if (HitOnScreen(host_->view(), p)) { | |
| 130 return false; | |
| 131 } | |
| 132 // Treat the bookmark as a content area when it in detached mode. | |
| 133 if (browser_view_->GetBookmarkBarView()->IsDetached() && | |
| 134 browser_view_->IsBookmarkBarVisible() && | |
| 135 HitOnScreen(browser_view_->GetBookmarkBarView(), p)) { | |
| 136 return true; | |
| 137 } | |
| 138 if (HitOnScreen(browser_view_->GetContentsView(), | |
|
sky
2011/05/03 18:38:32
put all on one line (don't wrap).
SteveT
2011/05/06 18:48:43
Done.
| |
| 139 p)) { | |
| 140 return true; | |
| 141 } | |
| 142 return false; | |
| 143 } | |
| 144 | |
| 145 // Tests if |p| in the root window's coordinate is within the |view|'s bound. | |
| 146 bool HitOnScreen(const views::View* view, const gfx::Point& p) { | |
| 147 gfx::Point origin(0, 0); | |
| 148 views::View::ConvertPointToScreen(view, &origin); | |
| 149 gfx::Rect new_bounds(origin, view->size()); | |
| 150 return new_bounds.Contains(p); | |
| 151 } | |
| 152 | |
| 153 CompactLocationBarViewHost* host_; | |
| 154 BrowserView* browser_view_; | |
| 155 gfx::NativeView top_level_window_; | |
| 156 bool observing_; | |
| 157 | |
| 158 DISALLOW_COPY_AND_ASSIGN(MouseObserver); | |
| 159 }; | |
| 160 #endif // !defined(OS_MACOSX) | |
| 161 | |
| 162 //////////////////////////////////////////////////////////////////////////////// | |
| 163 // CompactLocationBarViewHost, public: | |
| 164 | |
| 165 CompactLocationBarViewHost::CompactLocationBarViewHost( | |
| 166 BrowserView* browser_view) | |
|
sky
2011/05/03 18:38:32
indentation is off
SteveT
2011/05/06 18:48:43
Done.
| |
| 167 : DropdownBarHost(browser_view), | |
| 168 current_tab_model_index_(-1) { | |
| 169 auto_hide_timer_.reset(new base::OneShotTimer<CompactLocationBarViewHost>()); | |
| 170 mouse_observer_.reset(new MouseObserver(this, browser_view)); | |
| 171 CompactLocationBarView* clbv = new CompactLocationBarView(this); | |
|
sky
2011/05/03 18:38:32
document who owns clbv
SteveT
2011/05/06 18:48:43
Done.
| |
| 172 Init(clbv, clbv); | |
| 173 } | |
| 174 | |
| 175 CompactLocationBarViewHost::~CompactLocationBarViewHost() { | |
| 176 // This may happen if we are destroyed during cleanup. | |
| 177 if (browser_view() && browser_view()->browser() && | |
|
sky
2011/05/03 18:38:32
'&& browser_view' -> '&& browser_view'
SteveT
2011/05/06 18:48:43
Done.
| |
| 178 browser_view()->browser()->tabstrip_model()) { | |
| 179 browser_view()->browser()->tabstrip_model()->RemoveObserver(this); | |
| 180 } | |
| 181 MessageLoopForUI::current()->RemoveObserver(mouse_observer_.get()); | |
|
sky
2011/05/03 18:38:32
Remove this and have MouseObservers destructor do
SteveT
2011/05/06 18:48:43
Done.
| |
| 182 } | |
| 183 | |
| 184 void CompactLocationBarViewHost::StartAutoHideTimer() { | |
| 185 if (!IsVisible() || HasFocus()) | |
| 186 return; | |
| 187 | |
| 188 if (auto_hide_timer_->IsRunning()) { | |
| 189 // Restart the timer. | |
| 190 auto_hide_timer_->Reset(); | |
| 191 } else { | |
| 192 auto_hide_timer_->Start(base::TimeDelta::FromSeconds(kHideTimeoutInSeconds), | |
| 193 this, &CompactLocationBarViewHost::HideCallback); | |
| 194 } | |
| 195 } | |
| 196 | |
| 197 //////////////////////////////////////////////////////////////////////////////// | |
| 198 // LocationBarView::Delegate implementation: | |
| 199 TabContentsWrapper* CompactLocationBarViewHost::GetTabContentsWrapper() const { | |
| 200 return browser_view()->browser()->GetSelectedTabContentsWrapper(); | |
| 201 } | |
| 202 | |
| 203 InstantController* CompactLocationBarViewHost::GetInstant() { | |
| 204 return browser_view()->browser()->instant(); | |
| 205 } | |
| 206 | |
| 207 void CompactLocationBarViewHost::OnInputInProgress(bool in_progress) { | |
| 208 | |
|
sky
2011/05/03 18:38:32
remove empty line
SteveT
2011/05/06 18:48:43
Done.
| |
| 209 } | |
| 210 | |
| 211 //////////////////////////////////////////////////////////////////////////////// | |
| 212 // CompactLocationBarViewHost, views::AcceleratorTarget implementation: | |
| 213 | |
| 214 bool CompactLocationBarViewHost::AcceleratorPressed( | |
| 215 const views::Accelerator& accelerator) { | |
| 216 if (HasFocus()) { | |
| 217 DCHECK(view() != NULL); | |
| 218 views::FocusManager* focus_manager = view()->GetFocusManager(); | |
| 219 if (focus_manager) | |
| 220 focus_manager->ClearFocus(); | |
| 221 } | |
| 222 Hide(true); | |
| 223 return false; | |
| 224 } | |
| 225 | |
| 226 //////////////////////////////////////////////////////////////////////////////// | |
| 227 // CompactLocationBarViewHost, views::DropdownBarHost implementation: | |
| 228 | |
| 229 gfx::Rect CompactLocationBarViewHost::GetDialogPosition( | |
| 230 gfx::Rect avoid_overlapping_rect) { | |
| 231 if (!browser_view() || !browser_view()->browser() || | |
| 232 !browser_view()->browser()->tabstrip_model()) { | |
|
sky
2011/05/03 18:38:32
indentation is off
SteveT
2011/05/06 18:48:43
Done.
| |
| 233 return gfx::Rect(); | |
| 234 } | |
| 235 DCHECK_GE(current_tab_model_index_, 0); | |
| 236 if (!browser_view()->browser()->tabstrip_model()->ContainsIndex( | |
| 237 current_tab_model_index_)) { | |
| 238 return gfx::Rect(); | |
| 239 } | |
| 240 | |
| 241 gfx::Rect new_pos = GetBoundsUnderTab(current_tab_model_index_); | |
| 242 | |
| 243 if (animation_offset() > 0) | |
| 244 new_pos.Offset(0, std::min(0, -animation_offset())); | |
| 245 return new_pos; | |
| 246 } | |
| 247 | |
| 248 void CompactLocationBarViewHost::SetDialogPosition(const gfx::Rect& new_pos, | |
| 249 bool no_redraw) { | |
| 250 if (new_pos.IsEmpty()) | |
| 251 return; | |
| 252 | |
| 253 // Make sure the window edges are clipped to just the visible region. We need | |
| 254 // to do this before changing position, so that when we animate the closure | |
| 255 // of it it doesn't look like the window crumbles into the toolbar. | |
| 256 UpdateWindowEdges(new_pos); | |
| 257 | |
| 258 // TODO(oshima): Animate the window clipping like find-bar. | |
| 259 SetWidgetPositionNative(new_pos, no_redraw); | |
| 260 } | |
| 261 | |
| 262 //////////////////////////////////////////////////////////////////////////////// | |
| 263 // CompactLocationBarViewHost, views::TabStripModelObserver implementation: | |
| 264 | |
| 265 void CompactLocationBarViewHost::TabInsertedAt(TabContentsWrapper* contents, | |
| 266 int index, | |
| 267 bool foreground) { | |
| 268 if (foreground) { | |
| 269 Update(index, true); | |
|
sky
2011/05/03 18:38:32
This case (inserting a tab with foregroudn == true
SteveT
2011/05/06 18:48:43
Thanks for the pointer - no, we can just call it i
| |
| 270 StartAutoHideTimer(); | |
| 271 } | |
| 272 } | |
| 273 | |
| 274 void CompactLocationBarViewHost::TabClosingAt(TabStripModel* tab_strip_model, | |
| 275 TabContentsWrapper* contents, | |
| 276 int index) { | |
| 277 // TODO(oshima): We need to relocate the compact navigation bar if, | |
| 278 // the removed tab is not the one we are currently under | |
| 279 // but the tabstrip does not have the ideal location yet | |
| 280 // because the tabs are animating at this time. Need to investigate | |
| 281 // the best way to handle this case. | |
| 282 Hide(false); | |
|
sky
2011/05/03 18:38:32
Are you sure you want to hide when any tab is clos
SteveT
2011/05/06 18:48:43
The problem with hiding only when it's the current
| |
| 283 } | |
| 284 | |
| 285 void CompactLocationBarViewHost::TabSelectedAt(TabContentsWrapper* old_contents, | |
| 286 TabContentsWrapper* new_contents, | |
| 287 int index, | |
| 288 bool user_gesture) { | |
| 289 current_tab_model_index_ = index; | |
|
sky
2011/05/03 18:38:32
This can be invoked with the same index. Do you ne
SteveT
2011/05/06 18:48:43
No, I don't think we need to handle that case with
| |
| 290 if (new_contents && new_contents->tab_contents()->is_loading()) { | |
| 291 Show(false); | |
| 292 } else { | |
| 293 Hide(false); | |
| 294 } | |
| 295 } | |
| 296 | |
| 297 void CompactLocationBarViewHost::TabMoved(TabContentsWrapper* contents, | |
| 298 int from_index, | |
| 299 int to_index) { | |
| 300 Update(to_index, false); | |
|
sky
2011/05/03 18:38:32
Don't you only care if from_index == current_tab_m
SteveT
2011/05/06 18:48:43
Hm, is that expression not always true? It seems t
sky
2011/05/06 19:56:06
It's currently true, but I don't think you should
SteveT
2011/05/06 22:13:40
Done.
| |
| 301 StartAutoHideTimer(); | |
| 302 } | |
| 303 | |
| 304 void CompactLocationBarViewHost::TabChangedAt(TabContentsWrapper* contents, | |
| 305 int index, | |
| 306 TabChangeType change_type) { | |
| 307 if (IsCurrentTabIndex(index) && change_type == | |
| 308 TabStripModelObserver::LOADING_ONLY) { | |
| 309 bool was_not_visible = !IsVisible(); | |
|
sky
2011/05/03 18:38:32
indentation is off.
SteveT
2011/05/06 18:48:43
Done.
| |
| 310 TabContents* tab_contents = contents->tab_contents(); | |
| 311 Update(tab_contents, false); | |
| 312 if (was_not_visible) { | |
| 313 if (tab_contents->is_loading()) { | |
| 314 // Register to NavigationController LOAD_STOP so that we can autohide | |
| 315 // when loading is done. | |
| 316 if (!registrar_.IsRegistered(this, NotificationType::LOAD_STOP, | |
| 317 Source<NavigationController>(&tab_contents->controller()))) { | |
| 318 registrar_.Add(this, NotificationType::LOAD_STOP, | |
|
sky
2011/05/03 18:38:32
I don't see you removing the observer any where. D
SteveT
2011/05/06 18:48:43
We remove the observe below in CompactLocationBarV
| |
| 319 Source<NavigationController>(&tab_contents->controller())); | |
| 320 } | |
| 321 } else { | |
| 322 StartAutoHideTimer(); | |
| 323 } | |
| 324 } | |
| 325 } | |
| 326 } | |
| 327 | |
|
sky
2011/05/03 18:38:32
You should override TabReplacedAt. You may want a
SteveT
2011/05/06 18:48:43
TabReplacedAt is called when Instant replaces the
| |
| 328 void CompactLocationBarViewHost::TabReselected(int index) { | |
| 329 Update(index, true); | |
| 330 } | |
| 331 | |
| 332 //////////////////////////////////////////////////////////////////////////////// | |
| 333 // CompactLocationBarViewHost, NotificationObserver implementation: | |
| 334 | |
| 335 void CompactLocationBarViewHost::Observe(NotificationType type, | |
| 336 const NotificationSource& source, | |
| 337 const NotificationDetails& details) { | |
| 338 switch (type.value) { | |
| 339 case NotificationType::LOAD_STOP: { | |
| 340 StartAutoHideTimer(); | |
| 341 // This is one shot deal... | |
| 342 registrar_.Remove(this, NotificationType::LOAD_STOP, source); | |
| 343 break; | |
| 344 } | |
| 345 default: | |
| 346 NOTREACHED(); | |
| 347 } | |
| 348 } | |
| 349 | |
| 350 //////////////////////////////////////////////////////////////////////////////// | |
| 351 // CompactLocationBarViewHost public: | |
| 352 | |
| 353 gfx::Rect CompactLocationBarViewHost::GetBoundsUnderTab(int model_index) const { | |
| 354 // Get the position of the left-bottom corner of the tab on the | |
| 355 // widget. The widget of the tab is same as the widget of the | |
| 356 // BrowserView which is the parent of the host. | |
| 357 BaseTabStrip* tabstrip = | |
|
sky
2011/05/03 18:38:32
What does this code do if the user has enabled sid
SteveT
2011/05/06 18:48:43
We have some code in browser.cc that prevents side
| |
| 358 static_cast<BaseTabStrip*>(browser_view()->tabstrip()); | |
| 359 gfx::Rect tab_bounds = | |
| 360 tabstrip->ideal_bounds(tabstrip->ModelIndexToTabIndex(model_index)); | |
| 361 gfx::Rect navbar_bounds(gfx::Point(tab_bounds.x(), tab_bounds.height()), | |
| 362 view()->GetPreferredSize()); | |
| 363 | |
| 364 // For RTL case x() defines tab right corner. | |
| 365 if (base::i18n::IsRTL()) | |
| 366 navbar_bounds.Offset(tab_bounds.width(), 0); | |
| 367 navbar_bounds.Offset(tabstrip->x(), tabstrip->y()); | |
|
sky
2011/05/03 18:38:32
I'm not sure what coordinates system you want this
SteveT
2011/05/06 18:48:43
Yes, good suggestion. This removes the dependency
| |
| 368 | |
| 369 // The compact location bar must be smaller than browser_width. | |
| 370 int width = std::min(browser_view()->width(), | |
| 371 view()->GetPreferredSize().width()); | |
| 372 | |
| 373 #if defined(OS_WIN) | |
| 374 // The y-coordinate of the browser view is the distance from the top of the | |
| 375 // browser frame to the browser view. We need to offset the returned bounds by | |
| 376 // this amount since the drop down bar is drawn relative to the frame in | |
| 377 // Windows. | |
| 378 navbar_bounds.Offset(0, browser_view()->y()); | |
| 379 #endif | |
| 380 | |
| 381 // Try to center around the tab. | |
| 382 navbar_bounds.set_x(browser_view()->GetMirroredXInView( | |
| 383 navbar_bounds.x()) - ((width - tab_bounds.width()) / 2)); | |
| 384 | |
| 385 // Adjust the location to create the illusion that the compact location bar | |
| 386 // is a part of the spacer or bookmark bar, depending on which is showing. | |
| 387 if (browser_view()->IsBookmarkBarVisible() && | |
| 388 !browser_view()->GetBookmarkBarView()->IsDetached()) { | |
| 389 // TODO(stevet): Compact location bar does not have right background image | |
| 390 // yet, so kBookmarkBarLocationBarOverlap is tentative. Fix this once UI is | |
| 391 // settled. This may be entirely replaced by a popup CLB, anyway. | |
| 392 navbar_bounds.Offset(0, | |
| 393 browser_view()->GetBookmarkBarView()->bounds().height() + | |
| 394 kCompactNavbarSpacerHeight - kBookmarkBarLocationBarOverlap); | |
| 395 } else { | |
| 396 // TODO(stevet): kSpacerLocationbarOverlap is tentative as well, as above. | |
| 397 navbar_bounds.Offset(0, kCompactNavbarSpacerHeight - | |
| 398 kSpacerLocationbarOverlap); | |
| 399 } | |
| 400 | |
| 401 // TODO(stevet): Adjust to the right if there is an info bar visible. | |
| 402 return navbar_bounds.AdjustToFit(browser_view()->bounds()); | |
| 403 } | |
| 404 | |
| 405 void CompactLocationBarViewHost::Update(TabContents* contents, bool animate) { | |
| 406 // Don't animate if the bar is already shown. | |
| 407 bool showing_in_same_tab = animation()->IsShowing() && IsCurrentTab(contents); | |
| 408 current_tab_model_index_ = browser_view()->browser()->active_index(); | |
| 409 Hide(false); | |
| 410 GetCompactLocationBarView()->Update(contents); | |
| 411 Show(animate && !showing_in_same_tab); | |
| 412 // If the tab is loading, we must wait for the notification that it is done. | |
| 413 if (contents && !contents->is_loading()) { | |
| 414 // This will be a NOOP if we have focus. | |
| 415 // We never want to stay up, unless we have focus. | |
| 416 StartAutoHideTimer(); | |
| 417 } | |
| 418 } | |
| 419 | |
| 420 void CompactLocationBarViewHost::Update(int model_index, bool animate) { | |
|
sky
2011/05/03 18:38:32
Name these methods differently, especially since t
SteveT
2011/05/06 18:48:43
Second method:
Update -> UpdateOnTabChange
| |
| 421 DCHECK_GE(model_index, 0); | |
| 422 if (IsCurrentTabIndex(model_index) && animation()->IsShowing()) { | |
| 423 return; | |
| 424 } | |
| 425 current_tab_model_index_ = model_index; | |
| 426 Update(browser_view()->browser()->tabstrip_model()-> | |
| 427 GetTabContentsAt(model_index)->tab_contents(), animate); | |
| 428 } | |
| 429 | |
| 430 void CompactLocationBarViewHost::CancelAutoHideTimer() { | |
| 431 auto_hide_timer_->Stop(); | |
| 432 } | |
| 433 | |
| 434 void CompactLocationBarViewHost::SetEnabled(bool enabled) { | |
| 435 if (enabled) { | |
|
sky
2011/05/03 18:38:32
What if enabled is already true?
SteveT
2011/05/06 18:48:43
Currently we rely on the caller to behave correctl
sky
2011/05/06 19:56:06
Yes please.
SteveT
2011/05/06 22:13:40
Done.
| |
| 436 browser_view()->browser()->tabstrip_model()->AddObserver(this); | |
| 437 } else { | |
| 438 browser_view()->browser()->tabstrip_model()->RemoveObserver(this); | |
| 439 } | |
| 440 } | |
| 441 | |
| 442 void CompactLocationBarViewHost::Show(bool animate) { | |
| 443 CancelAutoHideTimer(); | |
| 444 mouse_observer_->Observe(MessageLoopForUI::current()); | |
| 445 DropdownBarHost::Show(animate); | |
| 446 host()->Show(); | |
| 447 } | |
| 448 | |
| 449 void CompactLocationBarViewHost::Hide(bool animate) { | |
| 450 CancelAutoHideTimer(); | |
| 451 mouse_observer_->StopObserving(MessageLoopForUI::current()); | |
| 452 host()->Hide(); | |
| 453 DropdownBarHost::Hide(animate); | |
| 454 } | |
| 455 | |
| 456 CompactLocationBarView* CompactLocationBarViewHost:: | |
| 457 GetCompactLocationBarView() { | |
| 458 return static_cast<CompactLocationBarView*>(view()); | |
| 459 } | |
| 460 | |
| 461 void CompactLocationBarViewHost::MoveWindowIfNecessary( | |
| 462 const gfx::Rect& selection_rect, | |
| 463 bool no_redraw) { | |
| 464 // We only move the window if one is currently shown. If we don't check this, | |
| 465 // then SetWidgetPosition below will end up making the Location Bar visible. | |
| 466 if (!IsVisible()) | |
| 467 return; | |
| 468 | |
| 469 gfx::Rect new_pos = GetDialogPosition(selection_rect); | |
| 470 SetDialogPosition(new_pos, no_redraw); | |
| 471 | |
| 472 // May need to redraw our frame to accommodate bookmark bar styles. | |
| 473 view()->SchedulePaint(); | |
| 474 } | |
| 475 | |
| 476 //////////////////////////////////////////////////////////////////////////////// | |
| 477 // CompactLocationBarViewHost private: | |
| 478 bool CompactLocationBarViewHost::HasFocus() { | |
| 479 DCHECK(view() != NULL); | |
| 480 views::FocusManager* focus_manager = view()->GetFocusManager(); | |
| 481 return focus_manager && view()->Contains(focus_manager->GetFocusedView()); | |
| 482 } | |
| 483 | |
| 484 void CompactLocationBarViewHost::HideCallback() { | |
| 485 if (IsVisible() && !HasFocus()) | |
| 486 Hide(true); | |
| 487 } | |
| 488 | |
| 489 bool CompactLocationBarViewHost::IsCurrentTabIndex(int index) { | |
| 490 return current_tab_model_index_ == index; | |
| 491 } | |
| 492 | |
| 493 bool CompactLocationBarViewHost::IsCurrentTab(TabContents* contents) { | |
| 494 TabStripModel* tab_strip_model = browser_view()->browser()->tabstrip_model(); | |
| 495 return tab_strip_model->ContainsIndex(current_tab_model_index_) && | |
| 496 tab_strip_model->GetTabContentsAt(current_tab_model_index_)-> | |
| 497 tab_contents() == contents; | |
| 498 } | |
| OLD | NEW |