Skip to content

Commit

Permalink
Adds some experimental stuff for tab preview: ability to determine max
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sky@chromium.org committed Aug 9, 2010
1 parent 8180e3a commit 6c4e663
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 32 deletions.
6 changes: 6 additions & 0 deletions chrome/browser/autocomplete/autocomplete_edit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions chrome/browser/autocomplete/autocomplete_edit.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions chrome/browser/autocomplete/autocomplete_edit_view_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions chrome/browser/autocomplete/autocomplete_popup_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions chrome/browser/autocomplete/autocomplete_popup_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_
6 changes: 6 additions & 0 deletions chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions chrome/browser/autocomplete/autocomplete_popup_view_gtk.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions chrome/browser/autocomplete/autocomplete_popup_view_mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions chrome/browser/autocomplete/autocomplete_popup_view_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,12 @@ - (NSInteger)highlightedRow;
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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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_;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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));
Expand All @@ -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
Expand Down Expand Up @@ -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:

Expand Down Expand Up @@ -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));
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 6c4e663

Please sign in to comment.