summaryrefslogtreecommitdiffstats
path: root/chrome/browser/views/app_launcher.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/views/app_launcher.cc')
-rw-r--r--chrome/browser/views/app_launcher.cc220
1 files changed, 52 insertions, 168 deletions
diff --git a/chrome/browser/views/app_launcher.cc b/chrome/browser/views/app_launcher.cc
index 240a926..a1a6bac 100644
--- a/chrome/browser/views/app_launcher.cc
+++ b/chrome/browser/views/app_launcher.cc
@@ -12,8 +12,7 @@
#include "base/message_loop.h"
#include "base/string_util.h"
#include "base/task.h"
-#include "chrome/browser/autocomplete/autocomplete_edit.h"
-#include "chrome/browser/autocomplete/autocomplete_edit_view.h"
+#include "chrome/app/chrome_dll_resource.h"
#include "chrome/browser/browser.h"
#include "chrome/browser/browser_window.h"
#include "chrome/browser/profile.h"
@@ -22,19 +21,9 @@
#include "chrome/browser/views/dom_view.h"
#include "chrome/browser/views/info_bubble.h"
#include "chrome/browser/views/frame/browser_view.h"
-#include "chrome/browser/views/toolbar_view.h"
+#include "chrome/browser/views/location_bar/location_bar_view.h"
#include "chrome/common/url_constants.h"
#include "views/widget/root_view.h"
-#include "views/widget/widget.h"
-
-#if defined(OS_WIN)
-#include "chrome/browser/autocomplete/autocomplete_edit_view_win.h"
-#elif defined(OS_LINUX)
-#include "chrome/browser/autocomplete/autocomplete_edit_view_gtk.h"
-#endif
-#if defined(OS_CHROMEOS)
-#include "chrome/browser/chromeos/status/status_area_view.h"
-#endif
namespace {
@@ -69,146 +58,14 @@ static GURL GetMenuURL() {
} // namespace
-////////////////////////////////////////////////////////////////////////////////
-// NavigationBar
-//
-// A navigation bar that is shown in the app launcher in compact navigation bar
-// mode.
-
-class NavigationBar : public views::View,
- public AutocompleteEditController {
- public:
- explicit NavigationBar(AppLauncher* app_launcher)
- : app_launcher_(app_launcher),
- location_entry_view_(NULL) {
- SetFocusable(true);
- location_entry_view_ = new views::NativeViewHost;
- AddChildView(location_entry_view_);
- set_border(views::Border::CreateSolidBorder(kNavigationBarBorderThickness,
- SK_ColorGRAY));
-
- AddChildView(&popup_positioning_view_);
- popup_positioning_view_.SetVisible(false);
- popup_positioning_view_.set_parent_owned(false);
- }
-
- virtual ~NavigationBar() {
- if (location_entry_view_->native_view())
- location_entry_view_->Detach();
- }
-
- // views::View overrides.
- virtual void Focus() {
- location_entry_->SetFocus();
- location_entry_->SelectAll(true);
- }
-
- virtual void ViewHierarchyChanged(bool is_add,
- views::View* parent,
- views::View* child) {
- if (!is_add || child != this)
- return;
-
- DCHECK(!location_entry_.get());
-
- Browser* browser = app_launcher_->browser();
-#if defined (OS_WIN)
- gfx::Font font;
- font = font.DeriveFont(kAutocompleteEditFontDelta);
- AutocompleteEditViewWin* autocomplete_view =
- new AutocompleteEditViewWin(font, this, browser->toolbar_model(),
- this, GetWidget()->GetNativeView(),
- browser->profile(),
- browser->command_updater(), false,
- &popup_positioning_view_);
- location_entry_.reset(autocomplete_view);
- autocomplete_view->Update(NULL);
- // The Update call above sets the autocomplete text to the current one in
- // the location bar, make sure to clear it.
- autocomplete_view->SetUserText(std::wstring());
-#elif defined(OS_LINUX) && defined(TOOLKIT_VIEWS)
- AutocompleteEditViewGtk* autocomplete_view =
- new AutocompleteEditViewGtk(this, browser->toolbar_model(),
- browser->profile(),
- browser->command_updater(), false,
- &popup_positioning_view_);
- autocomplete_view->Init();
- gtk_widget_show_all(autocomplete_view->GetNativeView());
- gtk_widget_hide(autocomplete_view->GetNativeView());
- location_entry_.reset(autocomplete_view);
-#else
- NOTIMPLEMENTED();
-#endif
- location_entry_view_->set_focus_view(this);
- location_entry_view_->Attach(location_entry_->GetNativeView());
- }
-
- virtual void Layout() {
- gfx::Rect bounds = GetLocalBounds(false);
- location_entry_view_->SetBounds(
- bounds.x() + kNavigationEntryXMargin + kNavigationEntryPadding,
- bounds.y() + kNavigationEntryYMargin,
- bounds.width() - 2 * (kNavigationEntryPadding +
- kNavigationEntryXMargin),
- bounds.height() - kNavigationEntryYMargin * 2);
-
- gfx::Rect popup_positioning_bounds(bounds);
- popup_positioning_bounds.Inset(0, -(kNavigationBarBorderThickness + 1));
- popup_positioning_view_.SetBounds(popup_positioning_bounds);
- }
-
- // AutocompleteController implementation.
- virtual void OnAutocompleteAccept(const GURL& url,
- WindowOpenDisposition disposition,
- PageTransition::Type transition,
- const GURL& alternate_nav_url) {
- app_launcher_->AddTabWithURL(url, transition);
- app_launcher_->Hide();
- }
- virtual void OnChanged() {}
- virtual void OnInputInProgress(bool in_progress) {}
- virtual void OnKillFocus() {}
- virtual void OnSetFocus() {
- views::FocusManager* focus_manager = GetFocusManager();
- if (!focus_manager) {
- NOTREACHED();
- return;
- }
- focus_manager->SetFocusedView(this);
- }
- virtual SkBitmap GetFavIcon() const {
- return SkBitmap();
- }
- virtual std::wstring GetTitle() const {
- return std::wstring();
- }
-
- private:
- AppLauncher* app_launcher_;
- views::NativeViewHost* location_entry_view_;
-#if defined(OS_WIN)
- scoped_ptr<AutocompleteEditViewWin> location_entry_;
-#elif defined(OS_LINUX) && defined(TOOLKIT_VIEWS)
- scoped_ptr<AutocompleteEditViewGtk> location_entry_;
-#else
- NOTIMPLEMENTED();
-#endif
-
- // This invisible view is provided to the popup in place of |this|, so the
- // popup can size itself against it using the same offsets it does with the
- // LocationBarView.
- views::View popup_positioning_view_;
-
- DISALLOW_COPY_AND_ASSIGN(NavigationBar);
-};
-
-////////////////////////////////////////////////////////////////////////////////
// InfoBubbleContentsView
//
// The view that contains the navigation bar and DOMUI.
// It is displayed in an info-bubble.
-class InfoBubbleContentsView : public views::View {
+class InfoBubbleContentsView : public views::View,
+ public LocationBarView::Delegate,
+ public CommandUpdater::CommandUpdaterDelegate {
public:
explicit InfoBubbleContentsView(AppLauncher* app_launcher);
~InfoBubbleContentsView();
@@ -224,23 +81,36 @@ class InfoBubbleContentsView : public views::View {
views::View* parent,
views::View* child);
+ // LocationBarView::Delegate implementation:
+ virtual TabContents* GetTabContents();
+ virtual void OnInputInProgress(bool in_progress) {}
+
+ // CommandUpdater::CommandUpdaterDelegate implementation:
+ virtual void ExecuteCommand(int id);
+
private:
// The application launcher displaying this info bubble.
AppLauncher* app_launcher_;
- // The navigation bar.
- NavigationBar* navigation_bar_;
+ // The location bar.
+ LocationBarView* location_bar_;
// The view containing the renderer view.
DOMView* dom_view_;
+ // CommandUpdater the location bar sends commands to.
+ CommandUpdater command_updater_;
+
DISALLOW_COPY_AND_ASSIGN(InfoBubbleContentsView);
};
InfoBubbleContentsView::InfoBubbleContentsView(AppLauncher* app_launcher)
: app_launcher_(app_launcher),
- navigation_bar_(NULL),
- dom_view_(NULL) {
+ location_bar_(NULL),
+ dom_view_(NULL),
+ ALLOW_THIS_IN_INITIALIZER_LIST(command_updater_(this)) {
+ // Allow the location bar to open URLs.
+ command_updater_.UpdateCommandEnabled(IDC_OPEN_CURRENT_URL, true);
DCHECK(app_launcher);
}
@@ -248,7 +118,7 @@ InfoBubbleContentsView::~InfoBubbleContentsView() {
}
void InfoBubbleContentsView::BubbleShown() {
- navigation_bar_->RequestFocus();
+ location_bar_->RequestFocus();
}
void InfoBubbleContentsView::ViewHierarchyChanged(
@@ -266,8 +136,21 @@ void InfoBubbleContentsView::ViewHierarchyChanged(
dom_view_->tab_contents()->set_delegate(app_launcher_);
dom_view_->LoadURL(GetMenuURL());
- navigation_bar_ = new NavigationBar(app_launcher_);
- AddChildView(navigation_bar_);
+ Browser* browser = app_launcher_->browser();
+ location_bar_ = new LocationBarView(browser->profile(),
+ &command_updater_,
+ browser->toolbar_model(),
+ this,
+ LocationBarView::APP_LAUNCHER);
+
+ location_bar_->set_border(
+ views::Border::CreateSolidBorder(1, SkColorSetRGB(205, 201, 201)));
+ AddChildView(location_bar_);
+ location_bar_->Init();
+}
+
+TabContents* InfoBubbleContentsView::GetTabContents() {
+ return app_launcher_->browser()->GetSelectedTabContents();
}
gfx::Size InfoBubbleContentsView::GetPreferredSize() {
@@ -280,24 +163,24 @@ void InfoBubbleContentsView::Layout() {
return;
gfx::Rect bounds = GetLocalBounds(false);
- int navigation_bar_height =
- kNavigationBarHeight + kNavigationEntryYMargin * 2;
- const views::Border* border = navigation_bar_->border();
- if (border) {
- gfx::Insets insets;
- border->GetInsets(&insets);
- navigation_bar_height += insets.height();
- }
- navigation_bar_->SetBounds(bounds.x(), bounds.y(),
- bounds.width(), navigation_bar_height);
- int render_y = navigation_bar_->bounds().bottom() +
- kNavigationBarBottomPadding;
+
+ location_bar_->SetBounds(bounds.x(), bounds.y(), bounds.width(),
+ location_bar_->GetPreferredSize().height());
+ int render_y = location_bar_->bounds().bottom() + kNavigationBarBottomPadding;
gfx::Size dom_view_size =
gfx::Size(width(), std::max(0, bounds.height() - render_y + bounds.y()));
dom_view_->SetBounds(bounds.x(), render_y,
dom_view_size.width(), dom_view_size.height());
}
+void InfoBubbleContentsView::ExecuteCommand(int id) {
+ // The user navigated by typing or selecting an entry in the location bar.
+ DCHECK_EQ(IDC_OPEN_CURRENT_URL, id);
+ GURL url(WideToUTF8(location_bar_->GetInputString()));
+ app_launcher_->AddTabWithURL(url, location_bar_->GetPageTransition());
+ app_launcher_->Hide();
+}
+
////////////////////////////////////////////////////////////////////////////////
// AppLauncher
@@ -358,7 +241,8 @@ void AppLauncher::OpenURLFromTab(TabContents* source,
PageTransition::Type transition) {
// TODO(jcivelli): we should call Browser::OpenApplicationTab(), we would need
// to access the app for this URL.
- AddTabWithURL(url, PageTransition::LINK);
+ // The user clicked an item in the app launcher contents.
+ AddTabWithURL(url, PageTransition::AUTO_BOOKMARK);
Hide();
}