Commit 0bd7d272 authored by Elly Fong-Jones's avatar Elly Fong-Jones Committed by Commit Bot

views: remove TreeView vertical margin

This change is needed for the Harmony treeview, but it also looks better in the
non-Harmony treeview, so it's unconditional in this CL.

This change also removes the special background/foreground colors from the
example treeview. While those were useful as a demonstration, they are quite
garish and distracting when screenshotting the treeview :).

Bug: 610428
Change-Id: Icf14b2e1d5b8c20a6d72550cfe57436b3f31cce4
Reviewed-on: https://chromium-review.googlesource.com/695563Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Elly Fong-Jones <ellyjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#506800}
parent 294b5f16
...@@ -41,7 +41,6 @@ namespace views { ...@@ -41,7 +41,6 @@ namespace views {
// Insets around the view. // Insets around the view.
static const int kHorizontalInset = 2; static const int kHorizontalInset = 2;
static const int kVerticalInset = 2;
// Padding before/after the image. // Padding before/after the image.
static const int kImagePadding = 4; static const int kImagePadding = 4;
// Size of the arrow region. // Size of the arrow region.
...@@ -607,9 +606,9 @@ void TreeView::OnPaint(gfx::Canvas* canvas) { ...@@ -607,9 +606,9 @@ void TreeView::OnPaint(gfx::Canvas* canvas) {
} }
} }
int min_row = std::max(0, (min_y - kVerticalInset) / row_height_); int min_row = std::max(0, min_y / row_height_);
int max_row = (max_y - kVerticalInset) / row_height_; int max_row = max_y / row_height_;
if ((max_y - kVerticalInset) % row_height_ != 0) if (max_y % row_height_ != 0)
max_row++; max_row++;
int current_row = root_row(); int current_row = root_row();
PaintRows(canvas, min_row, max_row, &root_, root_depth(), &current_row); PaintRows(canvas, min_row, max_row, &root_, root_depth(), &current_row);
...@@ -694,10 +693,9 @@ void TreeView::UpdatePreferredSize() { ...@@ -694,10 +693,9 @@ void TreeView::UpdatePreferredSize() {
if (!model_) if (!model_)
return; return;
preferred_size_.SetSize( preferred_size_.SetSize(root_.GetMaxWidth(text_offset_, root_shown_ ? 1 : 0) +
root_.GetMaxWidth(text_offset_, root_shown_ ? 1 : 0) + kTextHorizontalPadding * 2,
kTextHorizontalPadding * 2, row_height_ * GetRowCount());
row_height_ * GetRowCount() + kVerticalInset * 2);
} }
void TreeView::LayoutEditor() { void TreeView::LayoutEditor() {
...@@ -868,8 +866,8 @@ TreeView::InternalNode* TreeView::GetInternalNodeForModelNode( ...@@ -868,8 +866,8 @@ TreeView::InternalNode* TreeView::GetInternalNodeForModelNode(
gfx::Rect TreeView::GetBoundsForNode(InternalNode* node) { gfx::Rect TreeView::GetBoundsForNode(InternalNode* node) {
int row, ignored_depth; int row, ignored_depth;
row = GetRowForInternalNode(node, &ignored_depth); row = GetRowForInternalNode(node, &ignored_depth);
return gfx::Rect(bounds().x(), row * row_height_ + kVerticalInset, return gfx::Rect(bounds().x(), row * row_height_, bounds().width(),
bounds().width(), row_height_); row_height_);
} }
gfx::Rect TreeView::GetBackgroundBoundsForNode(InternalNode* node) { gfx::Rect TreeView::GetBackgroundBoundsForNode(InternalNode* node) {
...@@ -910,10 +908,8 @@ gfx::Rect TreeView::GetAuxiliaryTextBoundsForNode(InternalNode* node) { ...@@ -910,10 +908,8 @@ gfx::Rect TreeView::GetAuxiliaryTextBoundsForNode(InternalNode* node) {
gfx::Rect TreeView::GetForegroundBoundsForNodeImpl(InternalNode* node, gfx::Rect TreeView::GetForegroundBoundsForNodeImpl(InternalNode* node,
int row, int row,
int depth) { int depth) {
gfx::Rect rect(depth * kIndent + kHorizontalInset, gfx::Rect rect(depth * kIndent + kHorizontalInset, row * row_height_,
row * row_height_ + kVerticalInset, text_offset_ + node->text_width() + kTextHorizontalPadding * 2,
text_offset_ + node->text_width() +
kTextHorizontalPadding * 2,
row_height_); row_height_);
rect.set_x(GetMirroredXWithWidthInView(rect.x(), rect.width())); rect.set_x(GetMirroredXWithWidthInView(rect.x(), rect.width()));
return rect; return rect;
...@@ -940,7 +936,7 @@ int TreeView::GetRowForInternalNode(InternalNode* node, int* depth) { ...@@ -940,7 +936,7 @@ int TreeView::GetRowForInternalNode(InternalNode* node, int* depth) {
} }
TreeView::InternalNode* TreeView::GetNodeAtPoint(const gfx::Point& point) { TreeView::InternalNode* TreeView::GetNodeAtPoint(const gfx::Point& point) {
int row = (point.y() - kVerticalInset) / row_height_; int row = point.y() / row_height_;
int depth = -1; int depth = -1;
InternalNode* node = GetNodeByRow(row, &depth); InternalNode* node = GetNodeByRow(row, &depth);
if (!node) if (!node)
...@@ -1071,9 +1067,8 @@ bool TreeView::IsPointInExpandControl(InternalNode* node, ...@@ -1071,9 +1067,8 @@ bool TreeView::IsPointInExpandControl(InternalNode* node,
int row = GetRowForInternalNode(node, &depth); int row = GetRowForInternalNode(node, &depth);
int arrow_dx = depth * kIndent + kHorizontalInset; int arrow_dx = depth * kIndent + kHorizontalInset;
gfx::Rect arrow_bounds(bounds().x() + arrow_dx, gfx::Rect arrow_bounds(bounds().x() + arrow_dx, row * row_height_,
row * row_height_ + kVerticalInset, kArrowRegionSize, kArrowRegionSize, row_height_);
row_height_);
if (base::i18n::IsRTL()) if (base::i18n::IsRTL())
arrow_bounds.set_x(bounds().width() - arrow_dx - kArrowRegionSize); arrow_bounds.set_x(bounds().width() - arrow_dx - kArrowRegionSize);
return arrow_bounds.Contains(point); return arrow_bounds.Contains(point);
......
...@@ -22,21 +22,6 @@ class ExampleTreeViewDrawingProvider : public views::TreeViewDrawingProvider { ...@@ -22,21 +22,6 @@ class ExampleTreeViewDrawingProvider : public views::TreeViewDrawingProvider {
ExampleTreeViewDrawingProvider() {} ExampleTreeViewDrawingProvider() {}
~ExampleTreeViewDrawingProvider() override {} ~ExampleTreeViewDrawingProvider() override {}
SkColor GetBackgroundColorForNode(views::TreeView* tree_view,
ui::TreeModelNode* node) override {
if (tree_view->GetSelectedNode() == node)
return SK_ColorBLACK;
return views::TreeViewDrawingProvider::GetBackgroundColorForNode(tree_view,
node);
}
SkColor GetTextColorForNode(views::TreeView* tree_view,
ui::TreeModelNode* node) override {
if (tree_view->GetSelectedNode() == node)
return SkColorSetRGB(0x80, 0x80, 0x80);
return views::TreeViewDrawingProvider::GetTextColorForNode(tree_view, node);
}
base::string16 GetAuxiliaryTextForNode(views::TreeView* tree_view, base::string16 GetAuxiliaryTextForNode(views::TreeView* tree_view,
ui::TreeModelNode* node) override { ui::TreeModelNode* node) override {
if (tree_view->GetSelectedNode() == node) if (tree_view->GetSelectedNode() == node)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment