| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/chromeos/compact_location_bar_host.h" | 5 #include "chrome/browser/chromeos/compact_location_bar_host.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "app/slide_animation.h" | 9 #include "app/slide_animation.h" |
| 10 #include "base/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
| 11 #include "base/keyboard_codes.h" | 11 #include "base/keyboard_codes.h" |
| 12 #include "chrome/browser/browser.h" | 12 #include "chrome/browser/browser.h" |
| 13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/chromeos/compact_location_bar_view.h" | 14 #include "chrome/browser/chromeos/compact_location_bar_view.h" |
| 15 #include "chrome/browser/find_bar_controller.h" | 15 #include "chrome/browser/find_bar_controller.h" |
| 16 #include "chrome/browser/renderer_host/render_view_host.h" | 16 #include "chrome/browser/renderer_host/render_view_host.h" |
| 17 #include "chrome/browser/tab_contents/tab_contents.h" | 17 #include "chrome/browser/tab_contents/tab_contents.h" |
| 18 #include "chrome/browser/tab_contents/tab_contents_view.h" | 18 #include "chrome/browser/tab_contents/tab_contents_view.h" |
| 19 #include "chrome/browser/view_ids.h" | 19 #include "chrome/browser/view_ids.h" |
| 20 #include "chrome/browser/views/bookmark_bar_view.h" | 20 #include "chrome/browser/views/bookmark_bar_view.h" |
| 21 #include "chrome/browser/views/find_bar_view.h" | 21 #include "chrome/browser/views/find_bar_view.h" |
| 22 #include "chrome/browser/views/frame/browser_view.h" | 22 #include "chrome/browser/views/frame/browser_view.h" |
| 23 #include "chrome/browser/views/tabs/tab.h" | 23 #include "chrome/browser/views/tabs/base_tab_strip.h" |
| 24 #include "chrome/browser/views/tabs/tab_strip.h" | |
| 25 #include "views/controls/scrollbar/native_scroll_bar.h" | 24 #include "views/controls/scrollbar/native_scroll_bar.h" |
| 26 #include "views/focus/external_focus_tracker.h" | 25 #include "views/focus/external_focus_tracker.h" |
| 27 #include "views/focus/view_storage.h" | 26 #include "views/focus/view_storage.h" |
| 28 #include "views/widget/root_view.h" | 27 #include "views/widget/root_view.h" |
| 29 #include "views/widget/widget.h" | 28 #include "views/widget/widget.h" |
| 30 | 29 |
| 31 namespace chromeos { | 30 namespace chromeos { |
| 32 const int kDefaultLocationBarWidth = 300; | 31 const int kDefaultLocationBarWidth = 300; |
| 33 const int kHideTimeoutInSeconds = 2; | 32 const int kHideTimeoutInSeconds = 2; |
| 34 | 33 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 GdkWindow* top_level_window_; | 90 GdkWindow* top_level_window_; |
| 92 | 91 |
| 93 DISALLOW_COPY_AND_ASSIGN(MouseObserver); | 92 DISALLOW_COPY_AND_ASSIGN(MouseObserver); |
| 94 }; | 93 }; |
| 95 | 94 |
| 96 //////////////////////////////////////////////////////////////////////////////// | 95 //////////////////////////////////////////////////////////////////////////////// |
| 97 // CompactLocationBarHost, public: | 96 // CompactLocationBarHost, public: |
| 98 | 97 |
| 99 CompactLocationBarHost::CompactLocationBarHost(::BrowserView* browser_view) | 98 CompactLocationBarHost::CompactLocationBarHost(::BrowserView* browser_view) |
| 100 : DropdownBarHost(browser_view), | 99 : DropdownBarHost(browser_view), |
| 101 current_tab_index_(-1) { | 100 current_tab_model_index_(-1) { |
| 102 auto_hide_timer_.reset(new base::OneShotTimer<CompactLocationBarHost>()); | 101 auto_hide_timer_.reset(new base::OneShotTimer<CompactLocationBarHost>()); |
| 103 mouse_observer_.reset(new MouseObserver(this, browser_view)); | 102 mouse_observer_.reset(new MouseObserver(this, browser_view)); |
| 104 Init(new CompactLocationBarView(this)); | 103 Init(new CompactLocationBarView(this)); |
| 105 } | 104 } |
| 106 | 105 |
| 107 CompactLocationBarHost::~CompactLocationBarHost() { | 106 CompactLocationBarHost::~CompactLocationBarHost() { |
| 108 browser_view()->browser()->tabstrip_model()->RemoveObserver(this); | 107 browser_view()->browser()->tabstrip_model()->RemoveObserver(this); |
| 109 MessageLoopForUI::current()->RemoveObserver(mouse_observer_.get()); | 108 MessageLoopForUI::current()->RemoveObserver(mouse_observer_.get()); |
| 110 } | 109 } |
| 111 | 110 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 128 const views::Accelerator& accelerator) { | 127 const views::Accelerator& accelerator) { |
| 129 Hide(true); | 128 Hide(true); |
| 130 return false; | 129 return false; |
| 131 } | 130 } |
| 132 | 131 |
| 133 //////////////////////////////////////////////////////////////////////////////// | 132 //////////////////////////////////////////////////////////////////////////////// |
| 134 // CompactLocationBarHost, views::DropdownBarHost implementation: | 133 // CompactLocationBarHost, views::DropdownBarHost implementation: |
| 135 | 134 |
| 136 gfx::Rect CompactLocationBarHost::GetDialogPosition( | 135 gfx::Rect CompactLocationBarHost::GetDialogPosition( |
| 137 gfx::Rect avoid_overlapping_rect) { | 136 gfx::Rect avoid_overlapping_rect) { |
| 138 DCHECK_GE(current_tab_index_, 0); | 137 DCHECK_GE(current_tab_model_index_, 0); |
| 139 gfx::Rect new_pos = GetBoundsUnderTab(current_tab_index_); | 138 gfx::Rect new_pos = GetBoundsUnderTab(current_tab_model_index_); |
| 140 | 139 |
| 141 if (animation_offset() > 0) | 140 if (animation_offset() > 0) |
| 142 new_pos.Offset(0, std::min(0, -animation_offset())); | 141 new_pos.Offset(0, std::min(0, -animation_offset())); |
| 143 return new_pos; | 142 return new_pos; |
| 144 } | 143 } |
| 145 | 144 |
| 146 void CompactLocationBarHost::SetDialogPosition(const gfx::Rect& new_pos, | 145 void CompactLocationBarHost::SetDialogPosition(const gfx::Rect& new_pos, |
| 147 bool no_redraw) { | 146 bool no_redraw) { |
| 148 if (new_pos.IsEmpty()) | 147 if (new_pos.IsEmpty()) |
| 149 return; | 148 return; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 void CompactLocationBarHost::TabChangedAt(TabContents* contents, int index, | 198 void CompactLocationBarHost::TabChangedAt(TabContents* contents, int index, |
| 200 TabChangeType change_type) { | 199 TabChangeType change_type) { |
| 201 if (IsCurrentTabIndex(index) && IsVisible()) { | 200 if (IsCurrentTabIndex(index) && IsVisible()) { |
| 202 GetClbView()->Update(contents); | 201 GetClbView()->Update(contents); |
| 203 } | 202 } |
| 204 } | 203 } |
| 205 | 204 |
| 206 //////////////////////////////////////////////////////////////////////////////// | 205 //////////////////////////////////////////////////////////////////////////////// |
| 207 // CompactLocationBarHost public: | 206 // CompactLocationBarHost public: |
| 208 | 207 |
| 209 gfx::Rect CompactLocationBarHost::GetBoundsUnderTab(int index) const { | 208 gfx::Rect CompactLocationBarHost::GetBoundsUnderTab(int model_index) const { |
| 210 // Get the position of the left-bottom corner of the tab on the | 209 // Get the position of the left-bottom corner of the tab on the |
| 211 // widget. The widget of the tab is same as the widget of the | 210 // widget. The widget of the tab is same as the widget of the |
| 212 // BrowserView which is the parent of the host. | 211 // BrowserView which is the parent of the host. |
| 213 TabStrip* tabstrip = browser_view()->tabstrip()->AsTabStrip(); | 212 BaseTabStrip* tabstrip = browser_view()->tabstrip(); |
| 214 gfx::Rect bounds = tabstrip->GetIdealBounds(index); | 213 gfx::Rect bounds = |
| 214 tabstrip->ideal_bounds(tabstrip->ModelIndexToTabIndex(model_index)); |
| 215 gfx::Rect navbar_bounds(gfx::Point(bounds.x(), bounds.height()), | 215 gfx::Rect navbar_bounds(gfx::Point(bounds.x(), bounds.height()), |
| 216 view()->GetPreferredSize()); | 216 view()->GetPreferredSize()); |
| 217 | 217 |
| 218 // For RTL case x() defines tab right corner. | 218 // For RTL case x() defines tab right corner. |
| 219 if (base::i18n::IsRTL()) | 219 if (base::i18n::IsRTL()) |
| 220 navbar_bounds.set_x(navbar_bounds.x() + bounds.width()); | 220 navbar_bounds.set_x(navbar_bounds.x() + bounds.width()); |
| 221 navbar_bounds.set_x(navbar_bounds.x() + tabstrip->x()); | 221 navbar_bounds.set_x(navbar_bounds.x() + tabstrip->x()); |
| 222 navbar_bounds.set_y(navbar_bounds.y() + tabstrip->y()); | 222 navbar_bounds.set_y(navbar_bounds.y() + tabstrip->y()); |
| 223 | 223 |
| 224 // The compact location bar must be smaller than browser_width. | 224 // The compact location bar must be smaller than browser_width. |
| 225 int width = std::min(browser_view()->width(), | 225 int width = std::min(browser_view()->width(), |
| 226 view()->GetPreferredSize().width()); | 226 view()->GetPreferredSize().width()); |
| 227 | 227 |
| 228 // Try to center around the tab. | 228 // Try to center around the tab. |
| 229 navbar_bounds.set_x(browser_view()->MirroredXCoordinateInsideView( | 229 navbar_bounds.set_x(browser_view()->MirroredXCoordinateInsideView( |
| 230 navbar_bounds.x()) - ((width - bounds.width()) / 2)); | 230 navbar_bounds.x()) - ((width - bounds.width()) / 2)); |
| 231 | 231 |
| 232 if (browser_view()->IsBookmarkBarVisible() && | 232 if (browser_view()->IsBookmarkBarVisible() && |
| 233 !browser_view()->GetBookmarkBarView()->IsDetached()) { | 233 !browser_view()->GetBookmarkBarView()->IsDetached()) { |
| 234 // Adjust the location to create the illusion that the compact location bar | 234 // Adjust the location to create the illusion that the compact location bar |
| 235 // is a part of boolmark bar. | 235 // is a part of boolmark bar. |
| 236 // TODO(oshima): compact location bar does not have right background | 236 // TODO(oshima): compact location bar does not have right background |
| 237 // image yet, so -2 is tentative. Fix this once UI is settled. | 237 // image yet, so -2 is tentative. Fix this once UI is settled. |
| 238 navbar_bounds.set_y( | 238 navbar_bounds.set_y( |
| 239 browser_view()->GetBookmarkBarView()->bounds().bottom() - 2); | 239 browser_view()->GetBookmarkBarView()->bounds().bottom() - 2); |
| 240 } | 240 } |
| 241 return navbar_bounds.AdjustToFit(browser_view()->bounds()); | 241 return navbar_bounds.AdjustToFit(browser_view()->bounds()); |
| 242 } | 242 } |
| 243 | 243 |
| 244 void CompactLocationBarHost::Update(int index, | 244 void CompactLocationBarHost::Update(int model_index, |
| 245 bool animate_x, | 245 bool animate_x, |
| 246 bool select_all) { | 246 bool select_all) { |
| 247 DCHECK_GE(index, 0); | 247 DCHECK_GE(model_index, 0); |
| 248 if (IsCurrentTabIndex(index) && IsVisible()) { | 248 if (IsCurrentTabIndex(model_index) && IsVisible()) { |
| 249 return; | 249 return; |
| 250 } | 250 } |
| 251 current_tab_index_ = index; | 251 current_tab_model_index_ = model_index; |
| 252 // Don't aminate if the bar is already shown. | 252 // Don't aminate if the bar is already shown. |
| 253 bool animate = !animation()->IsShowing(); | 253 bool animate = !animation()->IsShowing(); |
| 254 Hide(false); | 254 Hide(false); |
| 255 GetClbView()->Update(browser_view()->browser()->GetSelectedTabContents()); | 255 GetClbView()->Update(browser_view()->browser()->GetSelectedTabContents()); |
| 256 GetClbView()->SetFocusAndSelection(select_all); | 256 GetClbView()->SetFocusAndSelection(select_all); |
| 257 Show(animate && animate_x); | 257 Show(animate && animate_x); |
| 258 } | 258 } |
| 259 | 259 |
| 260 void CompactLocationBarHost::CancelAutoHideTimer() { | 260 void CompactLocationBarHost::CancelAutoHideTimer() { |
| 261 auto_hide_timer_->Stop(); | 261 auto_hide_timer_->Stop(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 280 } | 280 } |
| 281 | 281 |
| 282 //////////////////////////////////////////////////////////////////////////////// | 282 //////////////////////////////////////////////////////////////////////////////// |
| 283 // CompactLocationBarHost private: | 283 // CompactLocationBarHost private: |
| 284 | 284 |
| 285 CompactLocationBarView* CompactLocationBarHost::GetClbView() { | 285 CompactLocationBarView* CompactLocationBarHost::GetClbView() { |
| 286 return static_cast<CompactLocationBarView*>(view()); | 286 return static_cast<CompactLocationBarView*>(view()); |
| 287 } | 287 } |
| 288 | 288 |
| 289 bool CompactLocationBarHost::IsCurrentTabIndex(int index) { | 289 bool CompactLocationBarHost::IsCurrentTabIndex(int index) { |
| 290 return current_tab_index_ == index; | 290 return current_tab_model_index_ == index; |
| 291 } | 291 } |
| 292 | 292 |
| 293 } // namespace chromeos | 293 } // namespace chromeos |
| OLD | NEW |