summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordeanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-27 08:13:43 +0000
committerdeanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-27 08:13:43 +0000
commitaa90e58c7e88cbcae7e4a7667e047c320a3fc0aa (patch)
treeb5941c6472ea95896937f83548d06941b48af26d
parent1b24f85903fca15bb44122c43c2e0e4548d1e094 (diff)
downloadchromium_src-aa90e58c7e88cbcae7e4a7667e047c320a3fc0aa.zip
chromium_src-aa90e58c7e88cbcae7e4a7667e047c320a3fc0aa.tar.gz
chromium_src-aa90e58c7e88cbcae7e4a7667e047c320a3fc0aa.tar.bz2
Use AutocompletePopupPositioner for the Linux Omnibox.
Now a few less magic numbers in exchange for a lot more plumbing. BUG=10966 Review URL: http://codereview.chromium.org/92127 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14592 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc12
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_gtk.h8
-rwxr-xr-xchrome/browser/autocomplete/autocomplete_popup_view_gtk.cc23
-rwxr-xr-xchrome/browser/autocomplete/autocomplete_popup_view_gtk.h4
-rw-r--r--chrome/browser/gtk/browser_toolbar_gtk.cc41
-rw-r--r--chrome/browser/gtk/browser_toolbar_gtk.h11
-rw-r--r--chrome/browser/gtk/location_bar_view_gtk.cc6
-rw-r--r--chrome/browser/gtk/location_bar_view_gtk.h7
8 files changed, 73 insertions, 39 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc
index 6e8efed..93e60ef 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc
@@ -35,7 +35,8 @@ AutocompleteEditViewGtk::AutocompleteEditViewGtk(
AutocompleteEditController* controller,
ToolbarModel* toolbar_model,
Profile* profile,
- CommandUpdater* command_updater)
+ CommandUpdater* command_updater,
+ AutocompletePopupPositioner* popup_positioner)
: text_view_(NULL),
tag_table_(NULL),
text_buffer_(NULL),
@@ -43,7 +44,8 @@ AutocompleteEditViewGtk::AutocompleteEditViewGtk(
secure_scheme_tag_(NULL),
insecure_scheme_tag_(NULL),
model_(new AutocompleteEditModel(this, controller, profile)),
- popup_view_(new AutocompletePopupViewGtk(this, model_.get(), profile)),
+ popup_view_(new AutocompletePopupViewGtk(this, model_.get(), profile,
+ popup_positioner)),
controller_(controller),
toolbar_model_(toolbar_model),
command_updater_(command_updater),
@@ -320,12 +322,6 @@ bool AutocompleteEditViewGtk::OnAfterPossibleChange() {
return something_changed;
}
-void AutocompleteEditViewGtk::BottomLeftPosWidth(int* x, int* y, int* width) {
- gdk_window_get_origin(text_view_->window, x, y);
- *y += text_view_->allocation.height;
- *width = text_view_->allocation.width;
-}
-
void AutocompleteEditViewGtk::HandleBeginUserAction() {
OnBeforePossibleChange();
}
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h
index 7ee00dd..33af52d 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.h
@@ -18,6 +18,7 @@
class AutocompleteEditController;
class AutocompleteEditModel;
+class AutocompletePopupPositioner;
class AutocompletePopupViewGtk;
class CommandUpdater;
class Profile;
@@ -29,7 +30,8 @@ class AutocompleteEditViewGtk : public AutocompleteEditView {
AutocompleteEditViewGtk(AutocompleteEditController* controller,
ToolbarModel* toolbar_model,
Profile* profile,
- CommandUpdater* command_updater);
+ CommandUpdater* command_updater,
+ AutocompletePopupPositioner* popup_positioner);
~AutocompleteEditViewGtk();
// Initialize, create the underlying widgets, etc.
@@ -82,10 +84,6 @@ class AutocompleteEditViewGtk : public AutocompleteEditView {
virtual void OnBeforePossibleChange();
virtual bool OnAfterPossibleChange();
- // Return the position (root coordinates) of the bottom left corner and width
- // of the location input box. Used by the popup view to position itself.
- void BottomLeftPosWidth(int* x, int* y, int* width);
-
private:
// Modeled like the Windows CHARRANGE. Represent a pair of cursor position
// offsets. Since GtkTextIters are invalid after the buffer is changed, we
diff --git a/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc b/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc
index b21152b..372f311 100755
--- a/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc
+++ b/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc
@@ -36,16 +36,10 @@ const GdkColor kURLTextColor = GDK_COLOR_RGB(0x00, 0x88, 0x00);
const GdkColor kDescriptionTextColor = GDK_COLOR_RGB(0x80, 0x80, 0x80);
const GdkColor kDescriptionSelectedTextColor = GDK_COLOR_RGB(0x78, 0x82, 0xb1);
-// TODO(deanm): This is added to extend past just the location box, and to
-// be below the the star and go button. Really this means that this should
-// probably plumb all the way back to the location bar view.
-const int kExtraSpace = 32;
// We have a 1 pixel border around the entire results popup.
const int kBorderThickness = 1;
// The vertical height of each result.
const int kHeightPerResult = 24;
-// Additional distance below the edit control.
-const int kTopMargin = 6;
// Width of the icons.
const int kIconWidth = 16;
// We want to vertically center the image in the result space.
@@ -181,9 +175,11 @@ void SetupLayoutForMatch(PangoLayout* layout,
AutocompletePopupViewGtk::AutocompletePopupViewGtk(
AutocompleteEditViewGtk* edit_view,
AutocompleteEditModel* edit_model,
- Profile* profile)
+ Profile* profile,
+ AutocompletePopupPositioner* popup_positioner)
: model_(new AutocompletePopupModel(this, edit_model, profile)),
edit_view_(edit_view),
+ popup_positioner_(popup_positioner),
window_(gtk_window_new(GTK_WINDOW_POPUP)),
gc_(NULL),
layout_(NULL),
@@ -267,14 +263,11 @@ AutocompletePopupModel* AutocompletePopupViewGtk::GetModel() {
}
void AutocompletePopupViewGtk::Show(size_t num_results) {
- gint x, y, width;
- edit_view_->BottomLeftPosWidth(&x, &y, &width);
- x -= kExtraSpace;
- width += kExtraSpace * 2;
-
- gtk_window_move(GTK_WINDOW(window_), x, y + kTopMargin);
- gtk_widget_set_size_request(window_, width,
- (num_results * kHeightPerResult) + (kBorderThickness * 2));
+ gfx::Rect rect = popup_positioner_->GetPopupBounds();
+ rect.set_height((num_results * kHeightPerResult) + (kBorderThickness * 2));
+
+ gtk_window_move(GTK_WINDOW(window_), rect.x(), rect.y());
+ gtk_widget_set_size_request(window_, rect.width(), rect.height());
gtk_widget_show(window_);
opened_ = true;
}
diff --git a/chrome/browser/autocomplete/autocomplete_popup_view_gtk.h b/chrome/browser/autocomplete/autocomplete_popup_view_gtk.h
index 0811e83..230eac2 100755
--- a/chrome/browser/autocomplete/autocomplete_popup_view_gtk.h
+++ b/chrome/browser/autocomplete/autocomplete_popup_view_gtk.h
@@ -25,7 +25,8 @@ class AutocompletePopupViewGtk : public AutocompletePopupView {
public:
AutocompletePopupViewGtk(AutocompleteEditViewGtk* edit_view,
AutocompleteEditModel* edit_model,
- Profile* profile);
+ Profile* profile,
+ AutocompletePopupPositioner* popup_positioner);
~AutocompletePopupViewGtk();
// Implement the AutocompletePopupView interface.
@@ -78,6 +79,7 @@ class AutocompletePopupViewGtk : public AutocompletePopupView {
scoped_ptr<AutocompletePopupModel> model_;
AutocompleteEditViewGtk* edit_view_;
+ AutocompletePopupPositioner* popup_positioner_;
// Our popup window, which is the only widget used, and we paint it on our
// own. This widget shouldn't be exposed outside of this class.
diff --git a/chrome/browser/gtk/browser_toolbar_gtk.cc b/chrome/browser/gtk/browser_toolbar_gtk.cc
index 0ceba4b..e87f32c 100644
--- a/chrome/browser/gtk/browser_toolbar_gtk.cc
+++ b/chrome/browser/gtk/browser_toolbar_gtk.cc
@@ -31,15 +31,31 @@
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
-const int BrowserToolbarGtk::kToolbarHeight = 38;
+namespace {
+
+// Height of the toolbar in pixels.
+const int kToolbarHeight = 38;
+
+// The amount of space between the bottom of the star and the top of the
+// Omnibox results popup window. We want a two pixel space between the bottom
+// and the results, but have some extra space below the buttons already.
+const int kPopupTopMargin = 0;
+
+// Space between the edge of the star/go button and the popup frame. We want
+// to leave 1 pixel on both side here so that the borders line up.
+const int kPopupLeftRightMargin = 1;
+
// For the back/forward dropdown menus, the time in milliseconds between
// when the user clicks and the popup menu appears.
-static const int kMenuTimerDelay = 500;
+const int kMenuTimerDelay = 500;
+
+} // namespace
BrowserToolbarGtk::BrowserToolbarGtk(Browser* browser)
: toolbar_(NULL),
location_bar_(new LocationBarViewGtk(browser->command_updater(),
- browser->toolbar_model())),
+ browser->toolbar_model(),
+ this)),
model_(browser->toolbar_model()),
browser_(browser),
profile_(NULL),
@@ -221,6 +237,25 @@ void BrowserToolbarGtk::UpdateTabContents(TabContents* contents,
location_bar_->Update(should_restore_state ? contents : NULL);
}
+gfx::Rect BrowserToolbarGtk::GetPopupBounds() const {
+ GtkWidget* star = star_->widget();
+ GtkWidget* go = go_->widget();
+
+ // TODO(deanm): The go and star buttons probably share the same window,
+ // so this could be optimized to only one origin request.
+ gint go_x, go_y;
+ gdk_window_get_origin(go->window, &go_x, &go_y);
+ go_x += go->allocation.x + go->allocation.width; // Right edge.
+
+ gint star_x, star_y;
+ gdk_window_get_origin(star->window, &star_x, &star_y);
+ star_x += star->allocation.x; // Left edge.
+ star_y += star->allocation.y + star->allocation.height; // Bottom edge.
+
+ return gfx::Rect(star_x + kPopupLeftRightMargin, star_y + kPopupTopMargin,
+ go_x - star_x - (2 * kPopupLeftRightMargin), 0);
+}
+
CustomDrawButton* BrowserToolbarGtk::BuildToolbarButton(
int normal_id, int active_id, int highlight_id, int depressed_id,
const std::string& localized_tooltip) {
diff --git a/chrome/browser/gtk/browser_toolbar_gtk.h b/chrome/browser/gtk/browser_toolbar_gtk.h
index ccf6dab..a8c4142 100644
--- a/chrome/browser/gtk/browser_toolbar_gtk.h
+++ b/chrome/browser/gtk/browser_toolbar_gtk.h
@@ -10,6 +10,7 @@
#include "base/scoped_ptr.h"
#include "base/task.h"
+#include "chrome/browser/autocomplete/autocomplete_popup_view.h"
#include "chrome/browser/command_updater.h"
#include "chrome/browser/gtk/menu_gtk.h"
#include "chrome/common/pref_member.h"
@@ -30,11 +31,9 @@ class ToolbarStarToggleGtk;
// events back to the Browser.
class BrowserToolbarGtk : public CommandUpdater::CommandObserver,
public MenuGtk::Delegate,
- public NotificationObserver {
+ public NotificationObserver,
+ public AutocompletePopupPositioner {
public:
- // Height of the toolbar, in pixels.
- static const int kToolbarHeight;
-
explicit BrowserToolbarGtk(Browser* browser);
virtual ~BrowserToolbarGtk();
@@ -69,6 +68,10 @@ class BrowserToolbarGtk : public CommandUpdater::CommandObserver,
ToolbarStarToggleGtk* star() { return star_.get(); }
+ // Implement AutocompletePopupPositioner, return the position of where the
+ // Omnibox results popup should go (from the star to the go buttons).
+ virtual gfx::Rect GetPopupBounds() const;
+
private:
// Builds a toolbar button with all the properties set.
CustomDrawButton* BuildToolbarButton(int normal_id,
diff --git a/chrome/browser/gtk/location_bar_view_gtk.cc b/chrome/browser/gtk/location_bar_view_gtk.cc
index dddb80d..4308c3b 100644
--- a/chrome/browser/gtk/location_bar_view_gtk.cc
+++ b/chrome/browser/gtk/location_bar_view_gtk.cc
@@ -44,10 +44,11 @@ const GdkColor LocationBarViewGtk::kBackgroundColorByLevel[3] = {
};
LocationBarViewGtk::LocationBarViewGtk(CommandUpdater* command_updater,
- ToolbarModel* toolbar_model)
+ ToolbarModel* toolbar_model, AutocompletePopupPositioner* popup_positioner)
: profile_(NULL),
command_updater_(command_updater),
toolbar_model_(toolbar_model),
+ popup_positioner_(popup_positioner),
disposition_(CURRENT_TAB),
transition_(PageTransition::TYPED) {
}
@@ -61,7 +62,8 @@ void LocationBarViewGtk::Init() {
location_entry_.reset(new AutocompleteEditViewGtk(this,
toolbar_model_,
profile_,
- command_updater_));
+ command_updater_,
+ popup_positioner_));
location_entry_->Init();
alignment_.Own(gtk_alignment_new(0.0, 0.0, 1.0, 1.0));
diff --git a/chrome/browser/gtk/location_bar_view_gtk.h b/chrome/browser/gtk/location_bar_view_gtk.h
index 0fd64fa..bf7a8f1 100644
--- a/chrome/browser/gtk/location_bar_view_gtk.h
+++ b/chrome/browser/gtk/location_bar_view_gtk.h
@@ -19,6 +19,7 @@
#include "webkit/glue/window_open_disposition.h"
class AutocompleteEditViewGtk;
+class AutocompletePopupPositioner;
class CommandUpdater;
class Profile;
class SkBitmap;
@@ -29,7 +30,8 @@ class LocationBarViewGtk : public AutocompleteEditController,
public LocationBar {
public:
LocationBarViewGtk(CommandUpdater* command_updater,
- ToolbarModel* toolbar_model);
+ ToolbarModel* toolbar_model,
+ AutocompletePopupPositioner* popup_positioner);
~LocationBarViewGtk();
void Init();
@@ -92,6 +94,9 @@ class LocationBarViewGtk : public AutocompleteEditController,
CommandUpdater* command_updater_;
ToolbarModel* toolbar_model_;
+ // We need to hold on to this just to it pass to the edit.
+ AutocompletePopupPositioner* popup_positioner_;
+
// When we get an OnAutocompleteAccept notification from the autocomplete
// edit, we save the input string so we can give it back to the browser on
// the LocationBar interface via GetInputString().