summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-09 15:18:17 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-09 15:18:17 +0000
commit6c4e6631acb0893ba00f035792e80942e2b00bd3 (patch)
tree2813210237c84fce72010ca1dff078a272770e03
parent8180e3ac5a503f0693fc550fe2163074de3cc7b2 (diff)
downloadchromium_src-6c4e6631acb0893ba00f035792e80942e2b00bd3.zip
chromium_src-6c4e6631acb0893ba00f035792e80942e2b00bd3.tar.gz
chromium_src-6c4e6631acb0893ba00f035792e80942e2b00bd3.tar.bz2
Adds some experimental stuff for tab preview: ability to determine max
screen position of popup and current url in omnibox. BUG=none TEST=none Review URL: http://codereview.chromium.org/3076040 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@55399 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit.cc6
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit.h7
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_win.h1
-rw-r--r--chrome/browser/autocomplete/autocomplete_popup_model.h2
-rw-r--r--chrome/browser/autocomplete/autocomplete_popup_view.h3
-rw-r--r--chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc6
-rw-r--r--chrome/browser/autocomplete/autocomplete_popup_view_gtk.h1
-rw-r--r--chrome/browser/autocomplete/autocomplete_popup_view_mac.h2
-rw-r--r--chrome/browser/autocomplete/autocomplete_popup_view_mac.mm6
-rw-r--r--chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc86
-rw-r--r--chrome/browser/views/autocomplete/autocomplete_popup_contents_view.h7
11 files changed, 95 insertions, 32 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_edit.cc b/chrome/browser/autocomplete/autocomplete_edit.cc
index 85eb29d..50321ba 100644
--- a/chrome/browser/autocomplete/autocomplete_edit.cc
+++ b/chrome/browser/autocomplete/autocomplete_edit.cc
@@ -127,6 +127,12 @@ void AutocompleteEditModel::RestoreState(const State& state) {
}
}
+GURL AutocompleteEditModel::CurrentURL() {
+ AutocompleteMatch match;
+ GetInfoForCurrentText(&match, NULL);
+ return match.destination_url;
+}
+
bool AutocompleteEditModel::UpdatePermanentText(
const std::wstring& new_permanent_text) {
// When there's a new URL, and the user is not editing anything or the edit
diff --git a/chrome/browser/autocomplete/autocomplete_edit.h b/chrome/browser/autocomplete/autocomplete_edit.h
index be1a79c..8c2a75b 100644
--- a/chrome/browser/autocomplete/autocomplete_edit.h
+++ b/chrome/browser/autocomplete/autocomplete_edit.h
@@ -102,10 +102,8 @@ class AutocompleteEditModel : public NotificationObserver {
void SetPopupModel(AutocompletePopupModel* popup_model);
-#ifdef UNIT_TEST
// It should only be used by testing code.
AutocompletePopupModel* popup_model() const { return popup_; }
-#endif
// Invoked when the profile has changed.
void SetProfile(Profile* profile);
@@ -119,6 +117,11 @@ class AutocompleteEditModel : public NotificationObserver {
// Restores local state from the saved |state|.
void RestoreState(const State& state);
+ // Returns the url for the current text. If the user has not edited the text
+ // this is the permanent url, otherwise it is the url the user would navigate
+ // to if they accept the current edit.
+ GURL CurrentURL();
+
// Called when the user wants to export the entire current text as a URL.
// Sets the url, and if known, the title and favicon.
void GetDataForURLExport(GURL* url, std::wstring* title, SkBitmap* favicon);
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_win.h b/chrome/browser/autocomplete/autocomplete_edit_view_win.h
index 2a6b2f5..24d0321 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_win.h
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_win.h
@@ -124,6 +124,7 @@ class AutocompleteEditViewWin
virtual bool OnAfterPossibleChange();
virtual gfx::NativeView GetNativeView() const;
virtual CommandUpdater* GetCommandUpdater();
+ int GetPopupMaxYCoordinate();
// Exposes custom IAccessible implementation to the overall MSAA hierarchy.
IAccessible* GetIAccessible();
diff --git a/chrome/browser/autocomplete/autocomplete_popup_model.h b/chrome/browser/autocomplete/autocomplete_popup_model.h
index e66903a..818ff2b 100644
--- a/chrome/browser/autocomplete/autocomplete_popup_model.h
+++ b/chrome/browser/autocomplete/autocomplete_popup_model.h
@@ -40,6 +40,8 @@ class AutocompletePopupModel : public NotificationObserver {
// Returns true if the popup is currently open.
bool IsOpen() const;
+ AutocompletePopupView* view() const { return view_; }
+
// Returns the AutocompleteController used by this popup.
AutocompleteController* autocomplete_controller() const {
return controller_.get();
diff --git a/chrome/browser/autocomplete/autocomplete_popup_view.h b/chrome/browser/autocomplete/autocomplete_popup_view.h
index 3fefdba..5eb8c82 100644
--- a/chrome/browser/autocomplete/autocomplete_popup_view.h
+++ b/chrome/browser/autocomplete/autocomplete_popup_view.h
@@ -41,6 +41,9 @@ class AutocompletePopupView {
// Returns the popup's model.
virtual AutocompletePopupModel* GetModel() = 0;
+
+ // Returns the max y coordinate of the popup in screen coordinates.
+ virtual int GetMaxYCoordinate() = 0;
};
#endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_POPUP_VIEW_H_
diff --git a/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc b/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc
index b451455..0d5a526 100644
--- a/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc
+++ b/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc
@@ -366,6 +366,12 @@ AutocompletePopupModel* AutocompletePopupViewGtk::GetModel() {
return model_.get();
}
+int AutocompletePopupViewGtk::GetMaxYCoordinate() {
+ // TODO: implement if match preview pans out.
+ NOTIMPLEMENTED();
+ return 0;
+}
+
void AutocompletePopupViewGtk::Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details) {
diff --git a/chrome/browser/autocomplete/autocomplete_popup_view_gtk.h b/chrome/browser/autocomplete/autocomplete_popup_view_gtk.h
index 61b9f5b..cae3798 100644
--- a/chrome/browser/autocomplete/autocomplete_popup_view_gtk.h
+++ b/chrome/browser/autocomplete/autocomplete_popup_view_gtk.h
@@ -40,6 +40,7 @@ class AutocompletePopupViewGtk : public AutocompletePopupView,
virtual void PaintUpdatesNow();
virtual void OnDragCanceled();
virtual AutocompletePopupModel* GetModel();
+ virtual int GetMaxYCoordinate();
// Overridden from NotificationObserver:
virtual void Observe(NotificationType type,
diff --git a/chrome/browser/autocomplete/autocomplete_popup_view_mac.h b/chrome/browser/autocomplete/autocomplete_popup_view_mac.h
index 5201c76..5dce4a4 100644
--- a/chrome/browser/autocomplete/autocomplete_popup_view_mac.h
+++ b/chrome/browser/autocomplete/autocomplete_popup_view_mac.h
@@ -72,6 +72,8 @@ class AutocompletePopupViewMac : public AutocompletePopupView {
// Returns the popup's model.
virtual AutocompletePopupModel* GetModel();
+ virtual int GetMaxYCoordinate();
+
// Opens the URL corresponding to the given |row|. If |force_background| is
// true, forces the URL to open in a background tab. Otherwise, determines
// the proper window open disposition from the modifier flags on |[NSApp
diff --git a/chrome/browser/autocomplete/autocomplete_popup_view_mac.mm b/chrome/browser/autocomplete/autocomplete_popup_view_mac.mm
index 14a2560..76e1bd1 100644
--- a/chrome/browser/autocomplete/autocomplete_popup_view_mac.mm
+++ b/chrome/browser/autocomplete/autocomplete_popup_view_mac.mm
@@ -459,6 +459,12 @@ AutocompletePopupModel* AutocompletePopupViewMac::GetModel() {
return model_.get();
}
+int AutocompletePopupViewMac::GetMaxYCoordinate() {
+ // TODO: implement if match preview pans out.
+ NOTIMPLEMENTED();
+ return 0;
+}
+
void AutocompletePopupViewMac::OpenURLForRow(int row, bool force_background) {
DCHECK_GE(row, 0);
diff --git a/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc b/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc
index 450eb6a..917e308 100644
--- a/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc
+++ b/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc
@@ -109,7 +109,8 @@ class AutocompleteResultView : public views::View {
public:
AutocompleteResultView(AutocompleteResultViewModel* model,
int model_index,
- const gfx::Font& font);
+ const gfx::Font& font,
+ const gfx::Font& bold_font);
virtual ~AutocompleteResultView();
// Updates the match used to paint the contents of this result view. We copy
@@ -122,6 +123,10 @@ class AutocompleteResultView : public views::View {
virtual void Layout();
virtual gfx::Size GetPreferredSize();
+ // Returns the preferred height for a single row.
+ static int GetPreferredHeight(const gfx::Font& font,
+ const gfx::Font& bold_font);
+
private:
// Precalculated data used to draw the portion of a match classification that
// fits entirely within one run.
@@ -186,9 +191,8 @@ class AutocompleteResultView : public views::View {
AutocompleteResultViewModel* model_;
size_t model_index_;
- // The fonts used to render the text in this row.
- gfx::Font normal_font_;
- gfx::Font bold_font_;
+ const gfx::Font normal_font_;
+ const gfx::Font bold_font_;
// Width of the ellipsis in the normal font.
int ellipsis_width_;
@@ -250,11 +254,12 @@ class AutocompleteResultView::MirroringContext {
AutocompleteResultView::AutocompleteResultView(
AutocompleteResultViewModel* model,
int model_index,
- const gfx::Font& font)
+ const gfx::Font& font,
+ const gfx::Font& bold_font)
: model_(model),
model_index_(model_index),
normal_font_(font),
- bold_font_(normal_font_.DeriveFont(0, gfx::Font::BOLD)),
+ bold_font_(bold_font),
ellipsis_width_(font.GetStringWidth(kEllipsis)),
mirroring_context_(new MirroringContext()),
match_(NULL, 0, false, AutocompleteMatch::URL_WHAT_YOU_TYPED) {
@@ -315,10 +320,17 @@ void AutocompleteResultView::Layout() {
}
gfx::Size AutocompleteResultView::GetPreferredSize() {
- int text_height = std::max(normal_font_.height(), bold_font_.height()) +
+ return gfx::Size(0, GetPreferredHeight(normal_font_, bold_font_));
+}
+
+// static
+int AutocompleteResultView::GetPreferredHeight(
+ const gfx::Font& font,
+ const gfx::Font& bold_font) {
+ int text_height = std::max(font.height(), bold_font.height()) +
(kTextVerticalPadding * 2);
int icon_height = icon_size_ + (kIconVerticalPadding * 2);
- return gfx::Size(0, std::max(icon_height, text_height));
+ return std::max(icon_height, text_height);
}
// static
@@ -602,6 +614,7 @@ AutocompletePopupContentsView::AutocompletePopupContentsView(
edit_view_(edit_view),
location_bar_(location_bar),
result_font_(font.DeriveFont(kEditFontAdjust)),
+ result_bold_font_(result_font_.DeriveFont(0, gfx::Font::BOLD)),
ignore_mouse_drag_(false),
ALLOW_THIS_IN_INITIALIZER_LIST(size_animation_(this)) {
// The following little dance is required because set_border() requires a
@@ -666,7 +679,8 @@ void AutocompletePopupContentsView::UpdatePopupAppearance() {
for (size_t i = 0; i < model_->result().size(); ++i) {
AutocompleteResultView* result_view;
if (i >= child_view_count) {
- result_view = new AutocompleteResultView(this, i, result_font_);
+ result_view =
+ new AutocompleteResultView(this, i, result_font_, result_bold_font_);
AddChildView(result_view);
} else {
result_view = static_cast<AutocompleteResultView*>(GetChildViewAt(i));
@@ -675,27 +689,7 @@ void AutocompletePopupContentsView::UpdatePopupAppearance() {
total_child_height += result_view->GetPreferredSize().height();
}
- // Calculate desired bounds.
- gfx::Rect location_bar_bounds(gfx::Point(), location_bar_->size());
- const views::Border* border = location_bar_->border();
- if (border) {
- // Adjust for the border so that the bubble and location bar borders are
- // aligned.
- gfx::Insets insets;
- border->GetInsets(&insets);
- location_bar_bounds.Inset(insets.left(), 0, insets.right(), 0);
- } else {
- // The normal location bar is drawn using a background graphic that includes
- // the border, so we inset by enough to make the edges line up, and the
- // bubble appear at the same height as the Star bubble.
- location_bar_bounds.Inset(LocationBarView::kNormalHorizontalEdgeThickness,
- 0);
- }
- gfx::Point location_bar_origin(location_bar_bounds.origin());
- views::View::ConvertPointToScreen(location_bar_, &location_bar_origin);
- location_bar_bounds.set_origin(location_bar_origin);
- gfx::Rect new_target_bounds(bubble_border_->GetBounds(location_bar_bounds,
- gfx::Size(location_bar_bounds.width(), total_child_height)));
+ gfx::Rect new_target_bounds = CalculateTargetBounds(total_child_height);
// If we're animating and our target height changes, reset the animation.
// NOTE: If we just reset blindly on _every_ update, then when the user types
@@ -734,6 +728,15 @@ AutocompletePopupModel* AutocompletePopupContentsView::GetModel() {
return model_.get();
}
+int AutocompletePopupContentsView::GetMaxYCoordinate() {
+ // Add one to kMaxMatches to account for the history shortcut that may be
+ // added.
+ return CalculateTargetBounds(
+ (static_cast<int>(AutocompleteResult::kMaxMatches) + 1) *
+ AutocompleteResultView::GetPreferredHeight(
+ result_font_, result_bold_font_)).bottom();
+}
+
////////////////////////////////////////////////////////////////////////////////
// AutocompletePopupContentsView, AutocompleteResultViewModel implementation:
@@ -983,3 +986,26 @@ size_t AutocompletePopupContentsView::GetIndexForPoint(
}
return AutocompletePopupModel::kNoMatch;
}
+
+gfx::Rect AutocompletePopupContentsView::CalculateTargetBounds(int h) {
+ gfx::Rect location_bar_bounds(gfx::Point(), location_bar_->size());
+ const views::Border* border = location_bar_->border();
+ if (border) {
+ // Adjust for the border so that the bubble and location bar borders are
+ // aligned.
+ gfx::Insets insets;
+ border->GetInsets(&insets);
+ location_bar_bounds.Inset(insets.left(), 0, insets.right(), 0);
+ } else {
+ // The normal location bar is drawn using a background graphic that includes
+ // the border, so we inset by enough to make the edges line up, and the
+ // bubble appear at the same height as the Star bubble.
+ location_bar_bounds.Inset(LocationBarView::kNormalHorizontalEdgeThickness,
+ 0);
+ }
+ gfx::Point location_bar_origin(location_bar_bounds.origin());
+ views::View::ConvertPointToScreen(location_bar_, &location_bar_origin);
+ location_bar_bounds.set_origin(location_bar_origin);
+ return bubble_border_->GetBounds(
+ location_bar_bounds, gfx::Size(location_bar_bounds.width(), h));
+}
diff --git a/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.h b/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.h
index fd861b4..3115787 100644
--- a/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.h
+++ b/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.h
@@ -64,6 +64,7 @@ class AutocompletePopupContentsView : public views::View,
virtual void PaintUpdatesNow();
virtual void OnDragCanceled();
virtual AutocompletePopupModel* GetModel();
+ virtual int GetMaxYCoordinate();
// Overridden from AutocompleteResultViewModel:
virtual bool IsSelectedIndex(size_t index) const;
@@ -119,6 +120,9 @@ class AutocompletePopupContentsView : public views::View,
// match at the specified point.
size_t GetIndexForPoint(const gfx::Point& point);
+ // Returns the target bounds given the specified content height.
+ gfx::Rect CalculateTargetBounds(int h);
+
// The popup that contains this view. We create this, but it deletes itself
// when its window is destroyed. This is a WeakPtr because it's possible for
// the OS to destroy the window and thus delete this object before we're
@@ -141,6 +145,9 @@ class AutocompletePopupContentsView : public views::View,
// by the edit that created us.
gfx::Font result_font_;
+ // The font used for portions that match the input.
+ gfx::Font result_bold_font_;
+
// If the user cancels a dragging action (i.e. by pressing ESC), we don't have
// a convenient way to release mouse capture. Instead we use this flag to
// simply ignore all remaining drag events, and the eventual mouse release