summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-07 00:52:31 +0000
committeroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-07 00:52:31 +0000
commitc83c9e683a9376cea1ef675bfe92f7dbb98d45f5 (patch)
treef50ff4edc61b1baa1dd10c8716af53fbeb7ce65e
parentea99c3abb5ad6121d94a4c4cf1ca683d4f0ebd90 (diff)
downloadchromium_src-c83c9e683a9376cea1ef675bfe92f7dbb98d45f5.zip
chromium_src-c83c9e683a9376cea1ef675bfe92f7dbb98d45f5.tar.gz
chromium_src-c83c9e683a9376cea1ef675bfe92f7dbb98d45f5.tar.bz2
Use dropdown bar for compact location bar.
* Refactored CompactLocationBar to Host/View to use DropdownBarHost/View. * Changed the logic to show/hide. Per cole's request, losing focus now hides the location bar. Following features are not implemented yet. * Window cripping while animating. * Adjust location when toolbar is shown (it's always under tab) * clipping autocomplete dropdown. Timer code is no longer used right now, but is left intentionally as we may put it back. BUG=None TEST=None Review URL: http://codereview.chromium.org/525018 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@35674 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/chromeos/browser_extenders.cc26
-rw-r--r--chrome/browser/chromeos/compact_location_bar_host.cc195
-rw-r--r--chrome/browser/chromeos/compact_location_bar_host.h105
-rw-r--r--chrome/browser/chromeos/compact_location_bar_view.cc (renamed from chrome/browser/chromeos/compact_location_bar.cc)159
-rw-r--r--chrome/browser/chromeos/compact_location_bar_view.h (renamed from chrome/browser/chromeos/compact_location_bar.h)64
-rw-r--r--chrome/browser/views/dropdown_bar_host.cc24
-rw-r--r--chrome/browser/views/dropdown_bar_host.h17
-rw-r--r--chrome/browser/views/find_bar_host.cc2
-rw-r--r--chrome/browser/views/frame/browser_view.cc3
-rw-r--r--chrome/browser/views/tabs/tab_strip.cc4
-rwxr-xr-xchrome/chrome_browser.gypi6
11 files changed, 421 insertions, 184 deletions
diff --git a/chrome/browser/chromeos/browser_extenders.cc b/chrome/browser/chromeos/browser_extenders.cc
index e59bbfc..2ef9d17 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.h"
+#include "chrome/browser/chromeos/compact_location_bar_host.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_.reset(
- new chromeos::CompactLocationBar(browser_view()));
+ compact_location_bar_host_.reset(
+ new chromeos::CompactLocationBarHost(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.
- compact_location_bar_->UpdateBounds(
- browser_view()->tabstrip()->GetSelectedTab());
+ int index = browser_view()->browser()->selected_index();
+ compact_location_bar_host_->Update(index, false);
}
*/
@@ -247,6 +247,7 @@ 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) {
@@ -254,11 +255,13 @@ class NormalExtender : public BrowserExtender,
}
virtual void OnMouseMovedOnTab(Tab* tab) {
- ShowCompactLocationBarUnderSelectedTab();
+ // TODO(oshima): remove this method from extender once we settled
+ // on the compact location bar behavior.
}
virtual void OnMouseExitedFromTab(Tab* tab) {
- compact_location_bar_->StartPopupTimer();
+ // TODO(oshima): remove this method from extender once we settled
+ // on the compact location bar behavior.
}
virtual bool ShouldForceMaximizedWindow() {
@@ -274,9 +277,8 @@ class NormalExtender : public BrowserExtender,
void ShowCompactLocationBarUnderSelectedTab() {
if (!compact_navigation_bar_enabled_)
return;
- compact_location_bar_->Update(
- browser_view()->tabstrip()->GetSelectedTab(),
- browser_view()->browser()->GetSelectedTabContents());
+ int index = browser_view()->browser()->selected_index();
+ compact_location_bar_host_->Update(index, true);
}
// Creates system menu.
@@ -320,8 +322,8 @@ class NormalExtender : public BrowserExtender,
// A toggle flag to show/hide the compact navigation bar.
bool compact_navigation_bar_enabled_;
- // CompactLocationBar view.
- scoped_ptr<chromeos::CompactLocationBar> compact_location_bar_;
+ // CompactLocationBarHost.
+ scoped_ptr<chromeos::CompactLocationBarHost> compact_location_bar_host_;
// A flag to specify if the browser window should be maximized.
bool force_maximized_window_;
diff --git a/chrome/browser/chromeos/compact_location_bar_host.cc b/chrome/browser/chromeos/compact_location_bar_host.cc
new file mode 100644
index 0000000..fafa967
--- /dev/null
+++ b/chrome/browser/chromeos/compact_location_bar_host.cc
@@ -0,0 +1,195 @@
+// 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
new file mode 100644
index 0000000..1d7b683
--- /dev/null
+++ b/chrome/browser/chromeos/compact_location_bar_host.h
@@ -0,0 +1,105 @@
+// 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/chromeos/compact_location_bar.cc b/chrome/browser/chromeos/compact_location_bar_view.cc
index e405475..9d4be31 100644
--- a/chrome/browser/chromeos/compact_location_bar.cc
+++ b/chrome/browser/chromeos/compact_location_bar_view.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.h"
+#include "chrome/browser/chromeos/compact_location_bar_view.h"
#include <gtk/gtk.h>
#include <algorithm>
@@ -13,12 +13,11 @@
#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"
@@ -26,119 +25,42 @@
#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;
-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>());
+CompactLocationBarView::CompactLocationBarView(CompactLocationBarHost* host)
+ : DropdownBarView(host),
+ reload_(NULL) {
set_background(views::Background::CreateStandardPanelBackground());
+ SetFocusable(true);
}
-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::~CompactLocationBarView() {
}
////////////////////////////////////////////////////////////////////////////////
-// 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);
- }
-}
-
-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);
-}
+// CompactLocationBarView public:
-void CompactLocationBar::UpdateBounds(const Tab* tab) {
- if (popup_ != NULL)
- popup_->SetBounds(GetBoundsUnderTab(tab));
+void CompactLocationBarView::SetFocusAndSelection() {
+ location_entry_->SetFocus();
+ location_entry_->SelectAll(true);
}
-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;
+void CompactLocationBarView::Update(const TabContents* contents) {
location_entry_->Update(contents);
- popup_->Show();
- // Set focus to the location entry.
- location_entry_->SetFocus();
-
- // Start popup timer.
- StartPopupTimer();
}
-////////////////////////////////////////////////////////////////////////////////
-// CompactLocationBar private:
-Browser* CompactLocationBar::browser() const {
- return browser_view_->browser();
-}
-
-void CompactLocationBar::CancelPopupTimer() {
- popup_timer_->Stop();
-}
+////////////////////////////////////////////////////////////////////////////////
+// CompactLocationBarView private:
-void CompactLocationBar::HidePopup() {
- current_contents_ = NULL;
- if (popup_) {
- CancelPopupTimer();
- popup_->Hide();
- }
+Browser* CompactLocationBarView::browser() const {
+ return host()->browser_view()->browser();
}
-void CompactLocationBar::Init() {
+void CompactLocationBarView::Init() {
ThemeProvider* tp = browser()->profile()->GetThemeProvider();
SkColor color = tp->GetColor(BrowserThemeProvider::COLOR_BUTTON_BACKGROUND);
SkBitmap* background = tp->GetBitmapNamed(IDR_THEME_BUTTON_BACKGROUND);
@@ -166,7 +88,6 @@ void CompactLocationBar::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());
@@ -184,7 +105,7 @@ void CompactLocationBar::Init() {
////////////////////////////////////////////////////////////////////////////////
// views::View overrides:
-gfx::Size CompactLocationBar::GetPreferredSize() {
+gfx::Size CompactLocationBarView::GetPreferredSize() {
if (!reload_)
return gfx::Size(); // Not initialized yet, do nothing.
@@ -193,7 +114,7 @@ gfx::Size CompactLocationBar::GetPreferredSize() {
return gfx::Size(500, sz.height());
}
-void CompactLocationBar::Layout() {
+void CompactLocationBarView::Layout() {
if (!reload_)
return; // Not initialized yet, do nothing.
@@ -211,28 +132,24 @@ void CompactLocationBar::Layout() {
cur_x = width() - sz.width();
}
-void CompactLocationBar::Paint(gfx::Canvas* canvas) {
+void CompactLocationBarView::Paint(gfx::Canvas* canvas) {
View::Paint(canvas);
}
-void CompactLocationBar::ViewHierarchyChanged(bool is_add, View* parent,
+void CompactLocationBarView::ViewHierarchyChanged(bool is_add, View* parent,
View* child) {
if (is_add && child == this)
Init();
}
-void CompactLocationBar::OnMouseEntered(const views::MouseEvent& event) {
- CancelPopupTimer();
-}
-
-void CompactLocationBar::OnMouseExited(const views::MouseEvent& event) {
- StartPopupTimer();
+void CompactLocationBarView::Focus() {
+ location_entry_->SetFocus();
}
////////////////////////////////////////////////////////////////////////////////
// views::ButtonListener overrides:
-void CompactLocationBar::ButtonPressed(views::Button* sender,
+void CompactLocationBarView::ButtonPressed(views::Button* sender,
const views::Event& event) {
int id = sender->tag();
browser()->ExecuteCommandWithDisposition(
@@ -242,7 +159,7 @@ void CompactLocationBar::ButtonPressed(views::Button* sender,
////////////////////////////////////////////////////////////////////////////////
// AutocompleteEditController overrides:
-void CompactLocationBar::OnAutocompleteAccept(
+void CompactLocationBarView::OnAutocompleteAccept(
const GURL& url,
WindowOpenDisposition disposition,
PageTransition::Type transition,
@@ -250,28 +167,36 @@ void CompactLocationBar::OnAutocompleteAccept(
browser()->OpenURL(url, GURL(), disposition, transition);
}
-void CompactLocationBar::OnChanged() {
+void CompactLocationBarView::OnChanged() {
// Other one does "DoLayout" here.
}
-void CompactLocationBar::OnInputInProgress(bool in_progress) {
+void CompactLocationBarView::OnKillFocus() {
+ clb_host()->Hide(true);
}
-SkBitmap CompactLocationBar::GetFavIcon() const {
+void CompactLocationBarView::OnSetFocus() {
+}
+
+void CompactLocationBarView::OnInputInProgress(bool in_progress) {
+}
+
+SkBitmap CompactLocationBarView::GetFavIcon() const {
return SkBitmap();
}
-std::wstring CompactLocationBar::GetTitle() const {
+std::wstring CompactLocationBarView::GetTitle() const {
return std::wstring();
}
////////////////////////////////////////////////////////////////////////////////
// BubblePositioner overrides:
-
-gfx::Rect CompactLocationBar::GetLocationStackBounds() const {
+gfx::Rect CompactLocationBarView::GetLocationStackBounds() const {
gfx::Point lower_left(0, height());
ConvertPointToScreen(this, &lower_left);
- return gfx::Rect(lower_left.x(), lower_left.y(), 700, 100);
+ gfx::Rect popup = gfx::Rect(lower_left.x(), lower_left.y(),
+ kCompactLocationBarDefaultWidth, 0);
+ return popup.AdjustToFit(GetWidget()->GetWindow()->GetBounds());
}
} // namespace chromeos
diff --git a/chrome/browser/chromeos/compact_location_bar.h b/chrome/browser/chromeos/compact_location_bar_view.h
index 83c46e6..4bf285d 100644
--- a/chrome/browser/chromeos/compact_location_bar.h
+++ b/chrome/browser/chromeos/compact_location_bar_view.h
@@ -2,13 +2,14 @@
// 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_H_
-#define CHROME_BROWSER_CHROMEOS_COMPACT_LOCATION_BAR_H_
+#ifndef CHROME_BROWSER_CHROMEOS_COMPACT_LOCATION_BAR_VIEW_H_
+#define CHROME_BROWSER_CHROMEOS_COMPACT_LOCATION_BAR_VIEW_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"
@@ -27,41 +28,27 @@ class NativeViewHost;
namespace chromeos {
-// CompactLocationBar is a version of location bar that is shown under
+// CompactLocationBarView 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.
-// TODO(oshima): re-implement w/o using a popup, like a FindBar.
-class CompactLocationBar : public views::View,
- public views::ButtonListener,
- public AutocompleteEditController,
- public BubblePositioner {
+class CompactLocationBarView : public DropdownBarView,
+ public views::ButtonListener,
+ public AutocompleteEditController,
+ public BubblePositioner {
public:
- explicit CompactLocationBar(BrowserView* browser_view);
- ~CompactLocationBar();
+ explicit CompactLocationBarView(CompactLocationBarHost* host);
+ ~CompactLocationBarView();
- // Returns the bounds to locale the compact location bar under the tab.
- gfx::Rect GetBoundsUnderTab(const Tab* tab) const;
+ // Claims focus for the text field and selects its contents.
+ virtual void SetFocusAndSelection();
- // (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);
+ void Update(const TabContents* contents);
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
- // CompactLocationBar.
+ // CompactLocationBarView.
void Init();
// Overridden from views::View.
@@ -70,8 +57,7 @@ class CompactLocationBar : public views::View,
virtual void Paint(gfx::Canvas* canvas);
virtual void ViewHierarchyChanged(bool is_add, views::View* parent,
views::View* child);
- virtual void OnMouseEntered(const views::MouseEvent& event);
- virtual void OnMouseExited(const views::MouseEvent& event);
+ virtual void Focus();
// Overridden from views::ButtonListener:
virtual void ButtonPressed(views::Button* sender, const views::Event& event);
@@ -82,8 +68,8 @@ class CompactLocationBar : public views::View,
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;
@@ -91,8 +77,9 @@ class CompactLocationBar : public views::View,
// BubblePositioner implementation.
virtual gfx::Rect GetLocationStackBounds() const;
- BrowserView* browser_view_;
- const TabContents* current_contents_;
+ CompactLocationBarHost* clb_host() {
+ return static_cast<CompactLocationBarHost*>(host());
+ }
views::ImageButton* reload_;
scoped_ptr<AutocompleteEditViewGtk> location_entry_;
@@ -101,14 +88,9 @@ class CompactLocationBar : public views::View,
// scoped_ptr<ToolbarStarToggleGtk> star_;
views::NativeViewHost* star_view_;
- scoped_ptr<base::OneShotTimer<CompactLocationBar> > popup_timer_;
-
- // A popup window to show the compact location bar.
- views::Widget* popup_;
-
- DISALLOW_COPY_AND_ASSIGN(CompactLocationBar);
+ DISALLOW_COPY_AND_ASSIGN(CompactLocationBarView);
};
} // namespace chromeos
-#endif // CHROME_BROWSER_CHROMEOS_COMPACT_LOCATION_BAR_H_
+#endif // CHROME_BROWSER_CHROMEOS_COMPACT_LOCATION_BAR_VIEW_H_
diff --git a/chrome/browser/views/dropdown_bar_host.cc b/chrome/browser/views/dropdown_bar_host.cc
index ee647d25..aa66672 100644
--- a/chrome/browser/views/dropdown_bar_host.cc
+++ b/chrome/browser/views/dropdown_bar_host.cc
@@ -26,7 +26,8 @@ bool DropdownBarHost::disable_animations_during_testing_ = false;
DropdownBarHost::DropdownBarHost(BrowserView* browser_view)
: browser_view_(browser_view),
animation_offset_(0),
- esc_accel_target_registered_(false) {
+ esc_accel_target_registered_(false),
+ is_visible_(false) {
}
void DropdownBarHost::Init(DropdownBarView* view) {
@@ -58,15 +59,20 @@ DropdownBarHost::~DropdownBarHost() {
focus_tracker_.reset(NULL);
}
-void DropdownBarHost::Show() {
+void DropdownBarHost::Show(bool animate) {
// 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 (disable_animations_during_testing_) {
- animation_->Reset(1);
- AnimationProgressed(animation_.get());
+ if (!animate || disable_animations_during_testing_) {
+ if (!is_visible_) {
+ // Don't re-start the animation.
+ is_visible_ = true;
+ animation_->Reset(1);
+ AnimationProgressed(animation_.get());
+ }
} else {
+ is_visible_ = true;
animation_->Reset();
animation_->Show();
}
@@ -81,10 +87,15 @@ 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();
}
}
@@ -94,7 +105,7 @@ void DropdownBarHost::StopAnimation() {
}
bool DropdownBarHost::IsVisible() const {
- return host_->IsVisible();
+ return is_visible_;
}
////////////////////////////////////////////////////////////////////////////////
@@ -149,6 +160,7 @@ 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 635ee18..58dcc17 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();
+ void Show(bool animate);
// 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,6 +143,11 @@ 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_;
@@ -172,6 +177,10 @@ 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 1e7cca7..212baf7 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();
+ DropdownBarHost::Show(true);
}
void FindBarHost::SetFocusAndSelection() {
diff --git a/chrome/browser/views/frame/browser_view.cc b/chrome/browser/views/frame/browser_view.cc
index f708963..5a230f3 100644
--- a/chrome/browser/views/frame/browser_view.cc
+++ b/chrome/browser/views/frame/browser_view.cc
@@ -445,6 +445,9 @@ 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 9c36b43..9a419db 100644
--- a/chrome/browser/views/tabs/tab_strip.cc
+++ b/chrome/browser/views/tabs/tab_strip.cc
@@ -782,7 +782,8 @@ void TabStrip::DestroyDraggedSourceTab(Tab* tab) {
}
gfx::Rect TabStrip::GetIdealBounds(int index) {
- DCHECK(index >= 0 && index < GetTabCount());
+ DCHECK_GE(index, 0);
+ DCHECK_LT(index, GetTabCount());
return tab_data_.at(index).ideal_bounds;
}
@@ -1953,6 +1954,7 @@ 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 d072aba..9389f1a 100755
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -244,8 +244,10 @@
'browser/chromeos/browser_extenders.cc',
'browser/chromeos/clock_menu_button.cc',
'browser/chromeos/clock_menu_button.h',
- 'browser/chromeos/compact_location_bar.cc',
- 'browser/chromeos/compact_location_bar.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_navigation_bar.cc',
'browser/chromeos/compact_navigation_bar.h',
'browser/chromeos/cros_library.cc',