diff options
-rw-r--r-- | chrome/browser/chromeos/browser_extenders.cc | 26 | ||||
-rw-r--r-- | chrome/browser/chromeos/compact_location_bar.cc (renamed from chrome/browser/chromeos/compact_location_bar_view.cc) | 159 | ||||
-rw-r--r-- | chrome/browser/chromeos/compact_location_bar.h (renamed from chrome/browser/chromeos/compact_location_bar_view.h) | 64 | ||||
-rw-r--r-- | chrome/browser/chromeos/compact_location_bar_host.cc | 195 | ||||
-rw-r--r-- | chrome/browser/chromeos/compact_location_bar_host.h | 105 | ||||
-rw-r--r-- | chrome/browser/views/dropdown_bar_host.cc | 24 | ||||
-rw-r--r-- | chrome/browser/views/dropdown_bar_host.h | 17 | ||||
-rw-r--r-- | chrome/browser/views/find_bar_host.cc | 2 | ||||
-rw-r--r-- | chrome/browser/views/frame/browser_view.cc | 3 | ||||
-rw-r--r-- | chrome/browser/views/tabs/tab_strip.cc | 4 | ||||
-rwxr-xr-x | chrome/chrome_browser.gypi | 6 |
11 files changed, 184 insertions, 421 deletions
diff --git a/chrome/browser/chromeos/browser_extenders.cc b/chrome/browser/chromeos/browser_extenders.cc index 2ef9d17..e59bbfc 100644 --- a/chrome/browser/chromeos/browser_extenders.cc +++ b/chrome/browser/chromeos/browser_extenders.cc @@ -9,7 +9,7 @@ #include "app/theme_provider.h" #include "base/command_line.h" #include "chrome/app/chrome_dll_resource.h" -#include "chrome/browser/chromeos/compact_location_bar_host.h" +#include "chrome/browser/chromeos/compact_location_bar.h" #include "chrome/browser/chromeos/compact_navigation_bar.h" #include "chrome/browser/chromeos/main_menu.h" #include "chrome/browser/chromeos/status_area_view.h" @@ -82,8 +82,8 @@ class NormalExtender : public BrowserExtender, browser_view()->AddChildView(main_menu_); Browser* browser = browser_view()->browser(); - compact_location_bar_host_.reset( - new chromeos::CompactLocationBarHost(browser_view())); + compact_location_bar_.reset( + new chromeos::CompactLocationBar(browser_view())); compact_navigation_bar_ = new chromeos::CompactNavigationBar(browser); browser_view()->AddChildView(compact_navigation_bar_); compact_navigation_bar_->Init(); @@ -151,8 +151,8 @@ class NormalExtender : public BrowserExtender, * Filed a bug: http://crbug.com/30612. if (compact_navigation_bar_->IsVisible()) { // Update the size and location of the compact location bar. - int index = browser_view()->browser()->selected_index(); - compact_location_bar_host_->Update(index, false); + compact_location_bar_->UpdateBounds( + browser_view()->tabstrip()->GetSelectedTab()); } */ @@ -247,7 +247,6 @@ class NormalExtender : public BrowserExtender, virtual void ToggleCompactNavigationBar() { compact_navigation_bar_enabled_ = !compact_navigation_bar_enabled_; compact_navigation_bar_->SetFocusable(compact_navigation_bar_enabled_); - compact_location_bar_host_->SetEnabled(compact_navigation_bar_enabled_); } virtual void OnMouseEnteredToTab(Tab* tab) { @@ -255,13 +254,11 @@ class NormalExtender : public BrowserExtender, } virtual void OnMouseMovedOnTab(Tab* tab) { - // TODO(oshima): remove this method from extender once we settled - // on the compact location bar behavior. + ShowCompactLocationBarUnderSelectedTab(); } virtual void OnMouseExitedFromTab(Tab* tab) { - // TODO(oshima): remove this method from extender once we settled - // on the compact location bar behavior. + compact_location_bar_->StartPopupTimer(); } virtual bool ShouldForceMaximizedWindow() { @@ -277,8 +274,9 @@ class NormalExtender : public BrowserExtender, void ShowCompactLocationBarUnderSelectedTab() { if (!compact_navigation_bar_enabled_) return; - int index = browser_view()->browser()->selected_index(); - compact_location_bar_host_->Update(index, true); + compact_location_bar_->Update( + browser_view()->tabstrip()->GetSelectedTab(), + browser_view()->browser()->GetSelectedTabContents()); } // Creates system menu. @@ -322,8 +320,8 @@ class NormalExtender : public BrowserExtender, // A toggle flag to show/hide the compact navigation bar. bool compact_navigation_bar_enabled_; - // CompactLocationBarHost. - scoped_ptr<chromeos::CompactLocationBarHost> compact_location_bar_host_; + // CompactLocationBar view. + scoped_ptr<chromeos::CompactLocationBar> compact_location_bar_; // A flag to specify if the browser window should be maximized. bool force_maximized_window_; diff --git a/chrome/browser/chromeos/compact_location_bar_view.cc b/chrome/browser/chromeos/compact_location_bar.cc index 9d4be31..e405475 100644 --- a/chrome/browser/chromeos/compact_location_bar_view.cc +++ b/chrome/browser/chromeos/compact_location_bar.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/chromeos/compact_location_bar_view.h" +#include "chrome/browser/chromeos/compact_location_bar.h" #include <gtk/gtk.h> #include <algorithm> @@ -13,11 +13,12 @@ #include "chrome/browser/autocomplete/autocomplete_edit_view_gtk.h" #include "chrome/browser/browser_list.h" #include "chrome/browser/browser_theme_provider.h" -#include "chrome/browser/chromeos/compact_location_bar_host.h" #include "chrome/browser/profile.h" #include "chrome/browser/view_ids.h" #include "chrome/browser/views/event_utils.h" #include "chrome/browser/views/frame/browser_view.h" +#include "chrome/browser/views/tabs/tab.h" +#include "chrome/browser/views/tabs/tab_strip.h" #include "grit/chromium_strings.h" #include "grit/generated_resources.h" #include "grit/theme_resources.h" @@ -25,42 +26,119 @@ #include "views/controls/button/image_button.h" #include "views/controls/native/native_view_host.h" #include "views/widget/widget.h" -#include "views/window/window.h" namespace chromeos { -const int kCompactLocationBarDefaultWidth = 700; -CompactLocationBarView::CompactLocationBarView(CompactLocationBarHost* host) - : DropdownBarView(host), - reload_(NULL) { +const int kDefaultLocationBarWidth = 300; +const int kHideTimeoutInSeconds = 2; + +CompactLocationBar::CompactLocationBar(BrowserView* browser_view) + : browser_view_(browser_view), + current_contents_(NULL), + reload_(NULL), + popup_(NULL) { + popup_timer_.reset(new base::OneShotTimer<CompactLocationBar>()); set_background(views::Background::CreateStandardPanelBackground()); - SetFocusable(true); } -CompactLocationBarView::~CompactLocationBarView() { +CompactLocationBar::~CompactLocationBar() { + if (popup_) { + // This is a hack to avoid deleting this twice. + // This problem will be gone once we eliminate a popup. + GetParent()->RemoveAllChildViews(false); + popup_->Close(); + popup_ = NULL; + } } //////////////////////////////////////////////////////////////////////////////// -// CompactLocationBarView public: +// CompactLocationBar public: + +void CompactLocationBar::StartPopupTimer() { + if (popup_ == NULL || !popup_->IsVisible()) + return; + if (popup_timer_->IsRunning()) { + // Restart the timer. + popup_timer_->Reset(); + } else { + popup_timer_->Start(base::TimeDelta::FromSeconds(kHideTimeoutInSeconds), + this, &CompactLocationBar::HidePopup); + } +} -void CompactLocationBarView::SetFocusAndSelection() { - location_entry_->SetFocus(); - location_entry_->SelectAll(true); +gfx::Rect CompactLocationBar::GetBoundsUnderTab(const Tab* tab) const { + // Get the position of the left-bottom corner of the tab on the screen + gfx::Point tab_left_bottom(0, tab->height()); + views::View::ConvertPointToScreen(tab, &tab_left_bottom); + // Get the position of the left edge of the window. + gfx::Point browser_left_top(0, 0); + views::View::ConvertPointToScreen(browser_view_, + &browser_left_top); + + // The compact location bar must be smaller than browser_width. + int width = std::min(browser_view_->width(), kDefaultLocationBarWidth); + + // Try to center around the tab, or align to the left of the window. + // TODO(oshima): handle RTL + int x = std::max(tab_left_bottom.x() - ((width - tab->width()) / 2), + browser_left_top.x()); + return gfx::Rect(x, tab_left_bottom.y(), width, 28); } -void CompactLocationBarView::Update(const TabContents* contents) { - location_entry_->Update(contents); +void CompactLocationBar::UpdateBounds(const Tab* tab) { + if (popup_ != NULL) + popup_->SetBounds(GetBoundsUnderTab(tab)); } +void CompactLocationBar::Update(const Tab* tab, const TabContents* contents) { + DCHECK(tab != NULL && contents != NULL); + if (current_contents_ == contents) { + StartPopupTimer(); + return; + } + CancelPopupTimer(); + HidePopup(); + + if (!popup_) { + popup_ = views::Widget::CreatePopupWidget( + views::Widget::Transparent, + views::Widget::AcceptEvents, + views::Widget::DeleteOnDestroy); + popup_->Init(NULL, GetBoundsUnderTab(tab)); + popup_->SetContentsView(this); + } else { + UpdateBounds(tab); + } + current_contents_ = contents; + location_entry_->Update(contents); + popup_->Show(); + // Set focus to the location entry. + location_entry_->SetFocus(); + + // Start popup timer. + StartPopupTimer(); +} //////////////////////////////////////////////////////////////////////////////// -// CompactLocationBarView private: +// CompactLocationBar private: -Browser* CompactLocationBarView::browser() const { - return host()->browser_view()->browser(); +Browser* CompactLocationBar::browser() const { + return browser_view_->browser(); } -void CompactLocationBarView::Init() { +void CompactLocationBar::CancelPopupTimer() { + popup_timer_->Stop(); +} + +void CompactLocationBar::HidePopup() { + current_contents_ = NULL; + if (popup_) { + CancelPopupTimer(); + popup_->Hide(); + } +} + +void CompactLocationBar::Init() { ThemeProvider* tp = browser()->profile()->GetThemeProvider(); SkColor color = tp->GetColor(BrowserThemeProvider::COLOR_BUTTON_BACKGROUND); SkBitmap* background = tp->GetBitmapNamed(IDR_THEME_BUTTON_BACKGROUND); @@ -88,6 +166,7 @@ void CompactLocationBarView::Init() { this, browser()->toolbar_model(), browser()->profile(), browser()->command_updater(), false, this)); + location_entry_->Init(); location_entry_->Update(browser()->GetSelectedTabContents()); gtk_widget_show_all(location_entry_->widget()); @@ -105,7 +184,7 @@ void CompactLocationBarView::Init() { //////////////////////////////////////////////////////////////////////////////// // views::View overrides: -gfx::Size CompactLocationBarView::GetPreferredSize() { +gfx::Size CompactLocationBar::GetPreferredSize() { if (!reload_) return gfx::Size(); // Not initialized yet, do nothing. @@ -114,7 +193,7 @@ gfx::Size CompactLocationBarView::GetPreferredSize() { return gfx::Size(500, sz.height()); } -void CompactLocationBarView::Layout() { +void CompactLocationBar::Layout() { if (!reload_) return; // Not initialized yet, do nothing. @@ -132,24 +211,28 @@ void CompactLocationBarView::Layout() { cur_x = width() - sz.width(); } -void CompactLocationBarView::Paint(gfx::Canvas* canvas) { +void CompactLocationBar::Paint(gfx::Canvas* canvas) { View::Paint(canvas); } -void CompactLocationBarView::ViewHierarchyChanged(bool is_add, View* parent, +void CompactLocationBar::ViewHierarchyChanged(bool is_add, View* parent, View* child) { if (is_add && child == this) Init(); } -void CompactLocationBarView::Focus() { - location_entry_->SetFocus(); +void CompactLocationBar::OnMouseEntered(const views::MouseEvent& event) { + CancelPopupTimer(); +} + +void CompactLocationBar::OnMouseExited(const views::MouseEvent& event) { + StartPopupTimer(); } //////////////////////////////////////////////////////////////////////////////// // views::ButtonListener overrides: -void CompactLocationBarView::ButtonPressed(views::Button* sender, +void CompactLocationBar::ButtonPressed(views::Button* sender, const views::Event& event) { int id = sender->tag(); browser()->ExecuteCommandWithDisposition( @@ -159,7 +242,7 @@ void CompactLocationBarView::ButtonPressed(views::Button* sender, //////////////////////////////////////////////////////////////////////////////// // AutocompleteEditController overrides: -void CompactLocationBarView::OnAutocompleteAccept( +void CompactLocationBar::OnAutocompleteAccept( const GURL& url, WindowOpenDisposition disposition, PageTransition::Type transition, @@ -167,36 +250,28 @@ void CompactLocationBarView::OnAutocompleteAccept( browser()->OpenURL(url, GURL(), disposition, transition); } -void CompactLocationBarView::OnChanged() { +void CompactLocationBar::OnChanged() { // Other one does "DoLayout" here. } -void CompactLocationBarView::OnKillFocus() { - clb_host()->Hide(true); +void CompactLocationBar::OnInputInProgress(bool in_progress) { } -void CompactLocationBarView::OnSetFocus() { -} - -void CompactLocationBarView::OnInputInProgress(bool in_progress) { -} - -SkBitmap CompactLocationBarView::GetFavIcon() const { +SkBitmap CompactLocationBar::GetFavIcon() const { return SkBitmap(); } -std::wstring CompactLocationBarView::GetTitle() const { +std::wstring CompactLocationBar::GetTitle() const { return std::wstring(); } //////////////////////////////////////////////////////////////////////////////// // BubblePositioner overrides: -gfx::Rect CompactLocationBarView::GetLocationStackBounds() const { + +gfx::Rect CompactLocationBar::GetLocationStackBounds() const { gfx::Point lower_left(0, height()); ConvertPointToScreen(this, &lower_left); - gfx::Rect popup = gfx::Rect(lower_left.x(), lower_left.y(), - kCompactLocationBarDefaultWidth, 0); - return popup.AdjustToFit(GetWidget()->GetWindow()->GetBounds()); + return gfx::Rect(lower_left.x(), lower_left.y(), 700, 100); } } // namespace chromeos diff --git a/chrome/browser/chromeos/compact_location_bar_view.h b/chrome/browser/chromeos/compact_location_bar.h index 4bf285d..83c46e6 100644 --- a/chrome/browser/chromeos/compact_location_bar_view.h +++ b/chrome/browser/chromeos/compact_location_bar.h @@ -2,14 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_CHROMEOS_COMPACT_LOCATION_BAR_VIEW_H_ -#define CHROME_BROWSER_CHROMEOS_COMPACT_LOCATION_BAR_VIEW_H_ +#ifndef CHROME_BROWSER_CHROMEOS_COMPACT_LOCATION_BAR_H_ +#define CHROME_BROWSER_CHROMEOS_COMPACT_LOCATION_BAR_H_ #include "base/basictypes.h" +#include "base/timer.h" #include "chrome/browser/bubble_positioner.h" #include "chrome/browser/autocomplete/autocomplete_edit.h" -#include "chrome/browser/chromeos/compact_location_bar_host.h" -#include "chrome/browser/views/dropdown_bar_view.h" #include "views/controls/button/button.h" #include "views/view.h" @@ -28,27 +27,41 @@ class NativeViewHost; namespace chromeos { -// CompactLocationBarView is a version of location bar that is shown under +// CompactLocationBar is a version of location bar that is shown under // a tab for short priod of used when Chrome is in the compact // navigation bar mode. -class CompactLocationBarView : public DropdownBarView, - public views::ButtonListener, - public AutocompleteEditController, - public BubblePositioner { +// TODO(oshima): re-implement w/o using a popup, like a FindBar. +class CompactLocationBar : public views::View, + public views::ButtonListener, + public AutocompleteEditController, + public BubblePositioner { public: - explicit CompactLocationBarView(CompactLocationBarHost* host); - ~CompactLocationBarView(); + explicit CompactLocationBar(BrowserView* browser_view); + ~CompactLocationBar(); - // Claims focus for the text field and selects its contents. - virtual void SetFocusAndSelection(); + // Returns the bounds to locale the compact location bar under the tab. + gfx::Rect GetBoundsUnderTab(const Tab* tab) const; - void Update(const TabContents* contents); + // (Re)Starts the popup timer that hides the popup after X seconds. + void StartPopupTimer(); + + // Updates the content and the location of the compact location bar. + void Update(const Tab* tab, const TabContents* contents); + + // Updates the location of the location bar popup under the given tab. + void UpdateBounds(const Tab* tab); private: Browser* browser() const; + // Cancels the popup timer. + void CancelPopupTimer(); + + // Hides the popup window. + void HidePopup(); + // Called when the view is added to the tree to initialize the - // CompactLocationBarView. + // CompactLocationBar. void Init(); // Overridden from views::View. @@ -57,7 +70,8 @@ class CompactLocationBarView : public DropdownBarView, virtual void Paint(gfx::Canvas* canvas); virtual void ViewHierarchyChanged(bool is_add, views::View* parent, views::View* child); - virtual void Focus(); + virtual void OnMouseEntered(const views::MouseEvent& event); + virtual void OnMouseExited(const views::MouseEvent& event); // Overridden from views::ButtonListener: virtual void ButtonPressed(views::Button* sender, const views::Event& event); @@ -68,8 +82,8 @@ class CompactLocationBarView : public DropdownBarView, PageTransition::Type transition, const GURL& alternate_nav_url); virtual void OnChanged(); - virtual void OnKillFocus(); - virtual void OnSetFocus(); + virtual void OnKillFocus() {} + virtual void OnSetFocus() {} virtual void OnInputInProgress(bool in_progress); virtual SkBitmap GetFavIcon() const; virtual std::wstring GetTitle() const; @@ -77,9 +91,8 @@ class CompactLocationBarView : public DropdownBarView, // BubblePositioner implementation. virtual gfx::Rect GetLocationStackBounds() const; - CompactLocationBarHost* clb_host() { - return static_cast<CompactLocationBarHost*>(host()); - } + BrowserView* browser_view_; + const TabContents* current_contents_; views::ImageButton* reload_; scoped_ptr<AutocompleteEditViewGtk> location_entry_; @@ -88,9 +101,14 @@ class CompactLocationBarView : public DropdownBarView, // scoped_ptr<ToolbarStarToggleGtk> star_; views::NativeViewHost* star_view_; - DISALLOW_COPY_AND_ASSIGN(CompactLocationBarView); + scoped_ptr<base::OneShotTimer<CompactLocationBar> > popup_timer_; + + // A popup window to show the compact location bar. + views::Widget* popup_; + + DISALLOW_COPY_AND_ASSIGN(CompactLocationBar); }; } // namespace chromeos -#endif // CHROME_BROWSER_CHROMEOS_COMPACT_LOCATION_BAR_VIEW_H_ +#endif // CHROME_BROWSER_CHROMEOS_COMPACT_LOCATION_BAR_H_ diff --git a/chrome/browser/chromeos/compact_location_bar_host.cc b/chrome/browser/chromeos/compact_location_bar_host.cc deleted file mode 100644 index fafa967..0000000 --- a/chrome/browser/chromeos/compact_location_bar_host.cc +++ /dev/null @@ -1,195 +0,0 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/chromeos/compact_location_bar_host.h" - -#include "app/slide_animation.h" -#include "base/keyboard_codes.h" -#include "chrome/browser/browser.h" -#include "chrome/browser/browser_process.h" -#include "chrome/browser/chromeos/compact_location_bar_view.h" -#include "chrome/browser/find_bar_controller.h" -#include "chrome/browser/renderer_host/render_view_host.h" -#include "chrome/browser/tab_contents/tab_contents.h" -#include "chrome/browser/tab_contents/tab_contents_view.h" -#include "chrome/browser/view_ids.h" -#include "chrome/browser/views/find_bar_view.h" -#include "chrome/browser/views/frame/browser_view.h" -#include "chrome/browser/views/tabs/tab.h" -#include "chrome/browser/views/tabs/tab_strip.h" -#include "views/controls/scrollbar/native_scroll_bar.h" -#include "views/focus/external_focus_tracker.h" -#include "views/focus/view_storage.h" -#include "views/widget/root_view.h" -#include "views/widget/widget.h" - -namespace chromeos { - -const int kDefaultLocationBarWidth = 300; -const int kHideTimeoutInSeconds = 2; - -//////////////////////////////////////////////////////////////////////////////// -// CompactLocationBarHost, public: - -CompactLocationBarHost::CompactLocationBarHost(BrowserView* browser_view) - : DropdownBarHost(browser_view), - current_tab_index_(-1) { - auto_hide_timer_.reset(new base::OneShotTimer<CompactLocationBarHost>()); - Init(new CompactLocationBarView(this)); -} - -CompactLocationBarHost::~CompactLocationBarHost() { - browser_view()->browser()->tabstrip_model()->RemoveObserver(this); -} - -void CompactLocationBarHost::StartAutoHideTimer() { - if (!host()->IsVisible()) - return; - if (auto_hide_timer_->IsRunning()) { - // Restart the timer. - auto_hide_timer_->Reset(); - } else { - auto_hide_timer_->Start(base::TimeDelta::FromSeconds(kHideTimeoutInSeconds), - this, &CompactLocationBarHost::HideCallback); - } -} - -//////////////////////////////////////////////////////////////////////////////// -// CompactLocationBarHost, views::AcceleratorTarget implementation: - -bool CompactLocationBarHost::AcceleratorPressed( - const views::Accelerator& accelerator) { - Hide(true); - return false; -} - -//////////////////////////////////////////////////////////////////////////////// -// CompactLocationBarHost, views::DropdownBarHost implementation: - -gfx::Rect CompactLocationBarHost::GetDialogPosition( - gfx::Rect avoid_overlapping_rect) { - DCHECK_GE(current_tab_index_, 0); - gfx::Rect new_pos = GetBoundsUnderTab(current_tab_index_); - - if (animation_offset() > 0) - new_pos.Offset(0, std::min(0, -animation_offset())); - - // TODO(oshima): Animate the window clipping like find-bar. - return new_pos; -} - -void CompactLocationBarHost::SetDialogPosition(const gfx::Rect& new_pos, - bool no_redraw) { - if (new_pos.IsEmpty()) - return; - - // TODO(oshima): Animate the window clipping like find-bar. - SetWidgetPositionNative(new_pos, no_redraw); -} - -//////////////////////////////////////////////////////////////////////////////// -// CompactLocationBarHost, views::TabStripModelObserver implementation: - -void CompactLocationBarHost::TabInsertedAt(TabContents* contents, - int index, - bool foreground) { - Hide(false); - // TODO(oshima): Consult UX team if we should show the location bar. -} - -void CompactLocationBarHost::TabClosingAt(TabContents* contents, int index) { - if (IsCurrentTabIndex(index)) { - Hide(false); - } else { - // TODO(oshima): We need to relocate the compact navigation bar here, - // but the tabstrip does not have the ideal location yet - // because the tabs are animating at this time. Need to investigate - // the best way to handle this case. - } -} - -void CompactLocationBarHost::TabSelectedAt(TabContents* old_contents, - TabContents* new_contents, - int index, - bool user_gesture) { - Hide(false); - if (user_gesture) { - // Show the compact location bar only when a user selected the tab. - Update(index, false); - } -} - -void CompactLocationBarHost::TabMoved(TabContents* contents, - int from_index, - int to_index, - bool pinned_state_changed) { - Update(to_index, false); -} - -void CompactLocationBarHost::TabChangedAt(TabContents* contents, int index, - TabChangeType change_type) { - if (IsCurrentTabIndex(index) && IsVisible()) { - GetClbView()->Update(contents); - } -} - -//////////////////////////////////////////////////////////////////////////////// -// CompactLocationBarHost public: - -gfx::Rect CompactLocationBarHost::GetBoundsUnderTab(int index) const { - // Get the position of the left-bottom corner of the tab on the - // widget. The widget of the tab is same as the widget of the - // BrowserView which is the parent of the host. - TabStrip* tabstrip = browser_view()->tabstrip(); - gfx::Rect bounds = tabstrip->GetIdealBounds(index); - gfx::Point tab_left_bottom(bounds.x(), bounds.height()); - views::View::ConvertPointToWidget(tabstrip, &tab_left_bottom); - - // The compact location bar must be smaller than browser_width. - int width = std::min(browser_view()->width(), kDefaultLocationBarWidth); - - // Try to center around the tab, or align to the left of the window. - // TODO(oshima): handle RTL - int x = std::max(tab_left_bottom.x() - ((width - bounds.width()) / 2), 0); - return gfx::Rect(x, tab_left_bottom.y(), width, 28); -} - -void CompactLocationBarHost::Update(int index, bool animate_x) { - DCHECK_GE(index, 0); - if (IsCurrentTabIndex(index) && IsVisible()) { - return; - } - current_tab_index_ = index; - // Don't aminate if the bar is already shown. - bool animate = !animation()->IsShowing(); - Hide(false); - GetClbView()->Update(browser_view()->browser()->GetSelectedTabContents()); - GetClbView()->SetFocusAndSelection(); - Show(animate && animate_x); -} - -void CompactLocationBarHost::CancelAutoHideTimer() { - auto_hide_timer_->Stop(); -} - -void CompactLocationBarHost::SetEnabled(bool enabled) { - if (enabled) { - browser_view()->browser()->tabstrip_model()->AddObserver(this); - } else { - browser_view()->browser()->tabstrip_model()->RemoveObserver(this); - } -} - -//////////////////////////////////////////////////////////////////////////////// -// CompactLocationBarHost private: - -CompactLocationBarView* CompactLocationBarHost::GetClbView() { - return static_cast<CompactLocationBarView*>(view()); -} - -bool CompactLocationBarHost::IsCurrentTabIndex(int index) { - return current_tab_index_ == index; -} - -} // namespace chromeos diff --git a/chrome/browser/chromeos/compact_location_bar_host.h b/chrome/browser/chromeos/compact_location_bar_host.h deleted file mode 100644 index 1d7b683..0000000 --- a/chrome/browser/chromeos/compact_location_bar_host.h +++ /dev/null @@ -1,105 +0,0 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_CHROMEOS_COMPACT_LOCATION_BAR_HOST_H_ -#define CHROME_BROWSER_CHROMEOS_COMPACT_LOCATION_BAR_HOST_H_ - -#include "app/animation.h" -#include "app/gfx/native_widget_types.h" -#include "base/gfx/rect.h" -#include "base/timer.h" -#include "chrome/browser/tabs/tab_strip_model.h" -#include "chrome/browser/views/dropdown_bar_host.h" -#include "views/controls/textfield/textfield.h" - -class BrowserView; -class TabContents; -class Tab; - -namespace chromeos { - -class CompactLocationBarView; - -//////////////////////////////////////////////////////////////////////////////// -// -// The CompactLocationBarHost implements the container window for the -// floating location bar. It uses the appropriate implementation from -// compact_location_bar_host_gtk.cc to draw its content and is -// responsible for showing, hiding, closing, and moving the window. -// -// There is one CompactLocationBarHost per BrowserView, and its state -// is updated whenever the selected Tab is changed. The -// CompactLocationBarHost is created when the BrowserView is attached -// to the frame's Widget for the first time, and enabled/disabled -// when the compact navigation bar is toggled. -// -//////////////////////////////////////////////////////////////////////////////// -class CompactLocationBarHost : public DropdownBarHost, - public TabStripModelObserver { - public: - explicit CompactLocationBarHost(BrowserView* browser_view); - virtual ~CompactLocationBarHost(); - - // Returns the bounds to locale the compact location bar under the tab. - gfx::Rect GetBoundsUnderTab(int tab_index) const; - - // Updates the content and the position of the compact location bar. - // |index| is the index of the tab the compact location bar - // will be attached to and |animate| specifies if the location bar - // should animate when shown. - void Update(int index, bool animate); - - // (Re)Starts the popup timer that hides the popup after X seconds. - void StartAutoHideTimer(); - - // Cancels the popup timer. - void CancelAutoHideTimer(); - - // Enable/disable the compact location bar. - void SetEnabled(bool enabled); - - // Overridden from views::AcceleratorTarget in DropdownBarHost class. - virtual bool AcceleratorPressed(const views::Accelerator& accelerator); - - // Overridden from DropdownBarHost class. - virtual gfx::Rect GetDialogPosition(gfx::Rect avoid_overlapping_rect); - virtual void SetDialogPosition(const gfx::Rect& new_pos, bool no_redraw); - - // Overriden from TabStripModelObserver class. - virtual void TabInsertedAt(TabContents* contents, - int index, - bool foreground); - virtual void TabClosingAt(TabContents* contents, int index); - virtual void TabSelectedAt(TabContents* old_contents, - TabContents* new_contents, - int index, - bool user_gesture); - virtual void TabMoved(TabContents* contents, - int from_index, - int to_index, - bool pinned_state_changed); - virtual void TabChangedAt(TabContents* contents, int index, - TabChangeType change_type); - - private: - void HideCallback() { - Hide(true); - } - - // Returns CompactLocationBarView. - CompactLocationBarView* GetClbView(); - - bool IsCurrentTabIndex(int index); - - // The index of the tab that the compact location bar is attached to. - int current_tab_index_; - - scoped_ptr<base::OneShotTimer<CompactLocationBarHost> > auto_hide_timer_; - - DISALLOW_COPY_AND_ASSIGN(CompactLocationBarHost); -}; - -} // namespace chromeos - -#endif // CHROME_BROWSER_CHROMEOS_COMPACT_LOCATION_BAR_HOST_H_ diff --git a/chrome/browser/views/dropdown_bar_host.cc b/chrome/browser/views/dropdown_bar_host.cc index aa66672..ee647d25 100644 --- a/chrome/browser/views/dropdown_bar_host.cc +++ b/chrome/browser/views/dropdown_bar_host.cc @@ -26,8 +26,7 @@ bool DropdownBarHost::disable_animations_during_testing_ = false; DropdownBarHost::DropdownBarHost(BrowserView* browser_view) : browser_view_(browser_view), animation_offset_(0), - esc_accel_target_registered_(false), - is_visible_(false) { + esc_accel_target_registered_(false) { } void DropdownBarHost::Init(DropdownBarView* view) { @@ -59,20 +58,15 @@ DropdownBarHost::~DropdownBarHost() { focus_tracker_.reset(NULL); } -void DropdownBarHost::Show(bool animate) { +void DropdownBarHost::Show() { // Stores the currently focused view, and tracks focus changes so that we can // restore focus when the dropdown widget is closed. focus_tracker_.reset(new views::ExternalFocusTracker(view_, focus_manager_)); - if (!animate || disable_animations_during_testing_) { - if (!is_visible_) { - // Don't re-start the animation. - is_visible_ = true; - animation_->Reset(1); - AnimationProgressed(animation_.get()); - } + if (disable_animations_during_testing_) { + animation_->Reset(1); + AnimationProgressed(animation_.get()); } else { - is_visible_ = true; animation_->Reset(); animation_->Show(); } @@ -87,15 +81,10 @@ bool DropdownBarHost::IsAnimating() const { } void DropdownBarHost::Hide(bool animate) { - if (!IsVisible()) { - return; - } if (animate && !disable_animations_during_testing_) { animation_->Reset(1.0); animation_->Hide(); } else { - StopAnimation(); - is_visible_ = false; host_->Hide(); } } @@ -105,7 +94,7 @@ void DropdownBarHost::StopAnimation() { } bool DropdownBarHost::IsVisible() const { - return is_visible_; + return host_->IsVisible(); } //////////////////////////////////////////////////////////////////////////////// @@ -160,7 +149,6 @@ void DropdownBarHost::AnimationEnded(const Animation* animation) { if (!animation_->IsShowing()) { // Animation has finished closing. host_->Hide(); - is_visible_ = false; } else { // Animation has finished opening. } diff --git a/chrome/browser/views/dropdown_bar_host.h b/chrome/browser/views/dropdown_bar_host.h index 58dcc17..635ee18 100644 --- a/chrome/browser/views/dropdown_bar_host.h +++ b/chrome/browser/views/dropdown_bar_host.h @@ -49,7 +49,7 @@ class DropdownBarHost : public views::AcceleratorTarget, // Returns true if the dropdown bar view is visible, or false otherwise. bool IsVisible() const; // Shows the dropdown bar. - void Show(bool animate); + void Show(); // Hides the dropdown bar. void Hide(bool animate); // Selects text in the entry field and set focus. @@ -84,13 +84,13 @@ class DropdownBarHost : public views::AcceleratorTarget, // having to poll it while it animates to open/closed status. static bool disable_animations_during_testing_; - // Returns the browser view that the dropdown belongs to. - BrowserView* browser_view() const { return browser_view_; } - protected: // Returns the dropdown bar view. DropdownBarView* view() const { return view_; } + // Returns the browser view that the dropdown belongs to. + BrowserView* browser_view() const { return browser_view_; } + // Returns the focus tracker. views::ExternalFocusTracker* focus_tracker() const { return focus_tracker_.get(); @@ -143,11 +143,6 @@ class DropdownBarHost : public views::AcceleratorTarget, const TabContents* contents, const views::Textfield::Keystroke& key_stroke); - // Returns the animation for the dropdown. - SlideAnimation* animation() { - return animation_.get(); - } - private: // The BrowserView that created us. BrowserView* browser_view_; @@ -177,10 +172,6 @@ class DropdownBarHost : public views::AcceleratorTarget, // dropdown bar. It contains the DropdownBarView. scoped_ptr<views::Widget> host_; - // A flag to manually manage visibility. GTK/X11 is asynchrnous and - // the state of the widget can be out of sync. - bool is_visible_; - DISALLOW_COPY_AND_ASSIGN(DropdownBarHost); }; diff --git a/chrome/browser/views/find_bar_host.cc b/chrome/browser/views/find_bar_host.cc index 212baf7..1e7cca7 100644 --- a/chrome/browser/views/find_bar_host.cc +++ b/chrome/browser/views/find_bar_host.cc @@ -51,7 +51,7 @@ FindBarHost::~FindBarHost() { } void FindBarHost::Show() { - DropdownBarHost::Show(true); + DropdownBarHost::Show(); } void FindBarHost::SetFocusAndSelection() { diff --git a/chrome/browser/views/frame/browser_view.cc b/chrome/browser/views/frame/browser_view.cc index 5a230f3..f708963 100644 --- a/chrome/browser/views/frame/browser_view.cc +++ b/chrome/browser/views/frame/browser_view.cc @@ -445,9 +445,6 @@ BrowserView::~BrowserView() { // notifications will call back into deleted objects). download_shelf_.reset(); - // Destory extender before destroying browser. - browser_extender_.reset(); - // Explicitly set browser_ to NULL. browser_.reset(); } diff --git a/chrome/browser/views/tabs/tab_strip.cc b/chrome/browser/views/tabs/tab_strip.cc index 9a419db..9c36b43 100644 --- a/chrome/browser/views/tabs/tab_strip.cc +++ b/chrome/browser/views/tabs/tab_strip.cc @@ -782,8 +782,7 @@ void TabStrip::DestroyDraggedSourceTab(Tab* tab) { } gfx::Rect TabStrip::GetIdealBounds(int index) { - DCHECK_GE(index, 0); - DCHECK_LT(index, GetTabCount()); + DCHECK(index >= 0 && index < GetTabCount()); return tab_data_.at(index).ideal_bounds; } @@ -1954,7 +1953,6 @@ void TabStrip::RemoveTabAt(int index) { removed->GetParent()->RemoveChildView(removed); delete removed; } - GenerateIdealBounds(); } void TabStrip::HandleGlobalMouseMoveEvent() { diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 9389f1a..d072aba 100755 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -244,10 +244,8 @@ 'browser/chromeos/browser_extenders.cc', 'browser/chromeos/clock_menu_button.cc', 'browser/chromeos/clock_menu_button.h', - 'browser/chromeos/compact_location_bar_host.cc', - 'browser/chromeos/compact_location_bar_host.h', - 'browser/chromeos/compact_location_bar_view.cc', - 'browser/chromeos/compact_location_bar_view.h', + 'browser/chromeos/compact_location_bar.cc', + 'browser/chromeos/compact_location_bar.h', 'browser/chromeos/compact_navigation_bar.cc', 'browser/chromeos/compact_navigation_bar.h', 'browser/chromeos/cros_library.cc', |