summaryrefslogtreecommitdiffstats
path: root/views
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-30 21:19:07 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-30 21:19:07 +0000
commita136016faff78780a4776c03e252e51d2f7cae37 (patch)
treeffbc1550c4275cd674f11410e15639f71daa67cf /views
parent9acc48601ea4aff4e5ec977c0dd089e887ba5ffd (diff)
downloadchromium_src-a136016faff78780a4776c03e252e51d2f7cae37.zip
chromium_src-a136016faff78780a4776c03e252e51d2f7cae37.tar.gz
chromium_src-a136016faff78780a4776c03e252e51d2f7cae37.tar.bz2
Adds link to bookmark bar that when clicked imports bookmarks. I also
added support for baselines to GridLayout. BUG=4374 TEST=On a new profile make sure the bookmark bar has a link to import bookmarks, click the link and make sure you can import your bookmarks. Review URL: http://codereview.chromium.org/440029 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@33336 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rwxr-xr-xviews/controls/label.cc6
-rw-r--r--views/controls/label.h3
-rw-r--r--views/grid_layout.cc67
-rw-r--r--views/grid_layout.h12
-rw-r--r--views/view.cc4
-rw-r--r--views/view.h4
6 files changed, 81 insertions, 15 deletions
diff --git a/views/controls/label.cc b/views/controls/label.cc
index ae98543..dff4165 100755
--- a/views/controls/label.cc
+++ b/views/controls/label.cc
@@ -99,6 +99,10 @@ gfx::Size Label::GetPreferredSize() {
return prefsize;
}
+int Label::GetBaseline() {
+ return GetInsets().top() + font_.baseline();
+}
+
int Label::ComputeMultiLineFlags() {
int flags = gfx::Canvas::MULTI_LINE;
#if !defined(OS_WIN)
@@ -439,7 +443,7 @@ gfx::Rect Label::GetTextBounds() {
gfx::Insets insets = GetInsets();
int avail_width = width() - insets.width();
// Respect the size set by the owner view
- text_size.set_width(std::min(avail_width, text_size.width()));
+ text_size.set_width(std::max(0, std::min(avail_width, text_size.width())));
int text_y = insets.top() +
(height() - text_size.height() - insets.height()) / 2;
diff --git a/views/controls/label.h b/views/controls/label.h
index 19d921d..76df4db 100644
--- a/views/controls/label.h
+++ b/views/controls/label.h
@@ -58,6 +58,9 @@ class Label : public View {
// Overridden to compute the size required to display this label
virtual gfx::Size GetPreferredSize();
+ // Overriden to return the baseline of the label.
+ virtual int GetBaseline();
+
// Return the height necessary to display this label with the provided width.
// This method is used to layout multi-line labels. It is equivalent to
// GetPreferredSize().height() if the receiver is not multi-line
diff --git a/views/grid_layout.cc b/views/grid_layout.cc
index 5b991fc..d35f42f 100644
--- a/views/grid_layout.cc
+++ b/views/grid_layout.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2009 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.
@@ -143,7 +143,7 @@ class LayoutElement {
int location_;
int size_;
- DISALLOW_EVIL_CONSTRUCTORS(LayoutElement);
+ DISALLOW_COPY_AND_ASSIGN(LayoutElement);
};
// Column -------------------------------------------------------------
@@ -213,7 +213,7 @@ class Column : public LayoutElement {
std::vector<Column*> same_size_columns_;
Column* master_column_;
- DISALLOW_EVIL_CONSTRUCTORS(Column);
+ DISALLOW_COPY_AND_ASSIGN(Column);
};
void Column::ResetSize() {
@@ -265,12 +265,15 @@ class Row : public LayoutElement {
: LayoutElement(resize_percent),
fixed_height_(fixed_height),
height_(height),
- column_set_(column_set) {
+ column_set_(column_set),
+ max_ascent_(0),
+ max_descent_(0) {
}
virtual ~Row() {}
virtual void ResetSize() {
+ max_ascent_ = max_descent_ = 0;
SetSize(height_);
}
@@ -278,13 +281,31 @@ class Row : public LayoutElement {
return column_set_;
}
+ // Adjusts the size to accomodate the specified ascent/descent.
+ void AdjustSizeForBaseline(int ascent, int descent) {
+ max_ascent_ = std::max(ascent, max_ascent_);
+ max_descent_ = std::max(descent, max_descent_);
+ AdjustSize(max_ascent_ + max_descent_);
+ }
+
+ int max_ascent() const {
+ return max_ascent_;
+ }
+
+ int max_descent() const {
+ return max_descent_;
+ }
+
private:
const bool fixed_height_;
const int height_;
// The column set used for this row; null for padding rows.
ColumnSet* column_set_;
- DISALLOW_EVIL_CONSTRUCTORS(Row);
+ int max_ascent_;
+ int max_descent_;
+
+ DISALLOW_COPY_AND_ASSIGN(Row);
};
// ViewState -------------------------------------------------------------
@@ -308,7 +329,8 @@ struct ViewState {
pref_width(pref_width),
pref_height(pref_height),
remaining_width(0),
- remaining_height(0) {
+ remaining_height(0),
+ baseline(-1) {
DCHECK(view && start_col >= 0 && start_row >= 0 && col_span > 0 &&
row_span > 0 && start_col < column_set->num_columns() &&
(start_col + col_span) <= column_set->num_columns());
@@ -336,6 +358,10 @@ struct ViewState {
// distributed to the columns/rows the view is in.
int remaining_width;
int remaining_height;
+
+ // The baseline. Only used if the view is vertically aligned along the
+ // baseline.
+ int baseline;
};
static bool CompareByColumnSpan(const ViewState* v1, const ViewState* v2) {
@@ -716,6 +742,9 @@ void GridLayout::AddView(View* view, int col_span, int row_span,
int pref_width, int pref_height) {
DCHECK(current_row_col_set_ && col_span > 0 && row_span > 0 &&
(next_column_ + col_span) <= current_row_col_set_->num_columns());
+ // We don't support baseline alignment of views spanning rows. Please add if
+ // you need it.
+ DCHECK(v_align != BASELINE || row_span == 1);
ViewState* state =
new ViewState(current_row_col_set_, view, next_column_, current_row_,
col_span, row_span, h_align, v_align, pref_width,
@@ -732,6 +761,9 @@ static void CalculateSize(int pref_size, GridLayout::Alignment alignment,
case GridLayout::LEADING:
// Nothing to do, location already points to start.
break;
+ case GridLayout::BASELINE: // If we were asked to align on baseline, but
+ // the view doesn't have a baseline, fall back
+ // to center.
case GridLayout::CENTER:
*location += (available_size - *size) / 2;
break;
@@ -783,8 +815,12 @@ void GridLayout::Layout(View* host) {
int y = rows_[view_state->start_row]->Location() + top_inset_;
int height = LayoutElement::TotalSize(view_state->start_row,
view_state->row_span, &rows_);
- CalculateSize(view_state->pref_height, view_state->v_align,
- &y, &height);
+ if (view_state->v_align == BASELINE && view_state->baseline != -1) {
+ y += rows_[view_state->start_row]->max_ascent() - view_state->baseline;
+ height = view_state->pref_height;
+ } else {
+ CalculateSize(view_state->pref_height, view_state->v_align, &y, &height);
+ }
view->SetBounds(x, y, width, height);
}
}
@@ -830,7 +866,9 @@ void GridLayout::SizeRowsAndColumns(bool layout, int width, int height,
// Reset the height of each row.
LayoutElement::ResetSizes(&rows_);
- // Do two things:
+ // Do the following:
+ // . If the view is aligned along it's baseline, obtain the baseline from the
+ // view and update the rows ascent/descent.
// . Reset the remaining_height of each view state.
// . If the width the view will be given is different than it's pref, ask
// for the height given a particularly width.
@@ -838,6 +876,10 @@ void GridLayout::SizeRowsAndColumns(bool layout, int width, int height,
i != view_states_.end() ; ++i) {
ViewState* view_state = *i;
view_state->remaining_height = view_state->pref_height;
+
+ if (view_state->v_align == BASELINE)
+ view_state->baseline = view_state->view->GetBaseline();
+
if (view_state->h_align == FILL) {
// The view is resizable. As the pref height may vary with the width,
// ask for the pref again.
@@ -855,13 +897,18 @@ void GridLayout::SizeRowsAndColumns(bool layout, int width, int height,
}
}
- // Update the height of each row from the views.
+ // Update the height/ascent/descent of each row from the views.
std::vector<ViewState*>::iterator view_states_iterator = view_states_.begin();
for (; view_states_iterator != view_states_.end() &&
(*view_states_iterator)->row_span == 1; ++view_states_iterator) {
ViewState* view_state = *view_states_iterator;
Row* row = rows_[view_state->start_row];
row->AdjustSize(view_state->remaining_height);
+ if (view_state->baseline != -1 &&
+ view_state->baseline <= view_state->pref_height) {
+ row->AdjustSizeForBaseline(view_state->baseline,
+ view_state->pref_height - view_state->baseline);
+ }
view_state->remaining_height = 0;
}
diff --git a/views/grid_layout.h b/views/grid_layout.h
index e3e7a62..9f07242 100644
--- a/views/grid_layout.h
+++ b/views/grid_layout.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2009 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.
@@ -81,7 +81,11 @@ class GridLayout : public LayoutManager {
TRAILING,
// The view is resized to fill the space.
- FILL
+ FILL,
+
+ // The view is aligned along the baseline. This is only valid for the
+ // vertical axis.
+ BASELINE
};
// An enumeration of the possible ways the size of a column may be obtained.
@@ -244,7 +248,7 @@ class GridLayout : public LayoutManager {
// Rows.
std::vector<Row*> rows_;
- DISALLOW_EVIL_CONSTRUCTORS(GridLayout);
+ DISALLOW_COPY_AND_ASSIGN(GridLayout);
};
// ColumnSet is used to define a set of columns. GridLayout may have any
@@ -346,7 +350,7 @@ class ColumnSet {
// for a description of what the master column is.
std::vector<Column*> master_columns_;
- DISALLOW_EVIL_CONSTRUCTORS(ColumnSet);
+ DISALLOW_COPY_AND_ASSIGN(ColumnSet);
};
} // namespace views
diff --git a/views/view.cc b/views/view.cc
index 3450e9a..f4869ec 100644
--- a/views/view.cc
+++ b/views/view.cc
@@ -143,6 +143,10 @@ gfx::Size View::GetPreferredSize() {
return gfx::Size();
}
+int View::GetBaseline() {
+ return -1;
+}
+
void View::SizeToPreferredSize() {
gfx::Size prefsize = GetPreferredSize();
if ((prefsize.width() != width()) || (prefsize.height() != height()))
diff --git a/views/view.h b/views/view.h
index 48d7b58..ae9a637 100644
--- a/views/view.h
+++ b/views/view.h
@@ -203,6 +203,10 @@ class View : public AcceleratorTarget {
// Get the size the View would like to be, if enough space were available.
virtual gfx::Size GetPreferredSize();
+ // Returns the baseline of this view, or -1 if this view has no baseline. The
+ // return value is relative to the preferred height.
+ virtual int GetBaseline();
+
// Convenience method that sizes this view to its preferred size.
void SizeToPreferredSize();