diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-02 19:36:25 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-02 19:36:25 +0000 |
commit | 53af24fa6d03dd0d5d505fd7994b2b5ea2feff9c (patch) | |
tree | 6c6f2d9de853fdf4ed4ba5ffe2f3cb9d49b060ae /views/controls | |
parent | 41635b2d4ed33ecc094856ee5dab6e307eaae231 (diff) | |
download | chromium_src-53af24fa6d03dd0d5d505fd7994b2b5ea2feff9c.zip chromium_src-53af24fa6d03dd0d5d505fd7994b2b5ea2feff9c.tar.gz chromium_src-53af24fa6d03dd0d5d505fd7994b2b5ea2feff9c.tar.bz2 |
Lands http://codereview.chromium.org/652010 for Thiago:
views: refactor out the "Alt" TableView feature.
BUG=34181
TEST=open bookmarks manager, type something in the search text-field, see if a
message is showed when there is no match and see if everything still works as
before.
Review URL: http://codereview.chromium.org/660380
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@40406 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/controls')
-rw-r--r-- | views/controls/table/table_view.cc | 49 | ||||
-rw-r--r-- | views/controls/table/table_view.h | 21 |
2 files changed, 68 insertions, 2 deletions
diff --git a/views/controls/table/table_view.cc b/views/controls/table/table_view.cc index 35a2399..0e5b46c 100644 --- a/views/controls/table/table_view.cc +++ b/views/controls/table/table_view.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c)2010 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. @@ -11,7 +11,9 @@ #include "app/gfx/canvas.h" #include "app/gfx/favicon_size.h" +#include "app/gfx/font.h" #include "app/gfx/icon_util.h" +#include "app/l10n_util.h" #include "app/l10n_util_win.h" #include "app/resource_bundle.h" #include "app/table_model.h" @@ -1118,6 +1120,22 @@ int TableView::GetColumnWidth(int column_id) { list_view_, static_cast<int>(i - visible_columns_.begin())); } +void TableView::PaintAltText() { + if (alt_text_.empty()) + return; + + HDC dc = GetDC(GetNativeControlHWND()); + gfx::Font font = GetAltTextFont(); + gfx::Rect bounds = GetAltTextBounds(); + gfx::Canvas canvas(bounds.width(), bounds.height(), false); + // Pad by 1 for halo. + canvas.DrawStringWithHalo(alt_text_, font, SK_ColorDKGRAY, SK_ColorWHITE, 1, + 1, bounds.width() - 2, bounds.height() - 2, + l10n_util::DefaultCanvasTextAlignment()); + canvas.getTopPlatformDevice().drawToHDC(dc, bounds.x(), bounds.y(), NULL); + ReleaseDC(GetNativeControlHWND(), dc); +} + LRESULT TableView::OnCustomDraw(NMLVCUSTOMDRAW* draw_info) { switch (draw_info->nmcd.dwDrawStage) { case CDDS_PREPAINT: { @@ -1333,6 +1351,18 @@ void TableView::SetPreferredSize(const gfx::Size& size) { PreferredSizeChanged(); } +void TableView::SetAltText(const std::wstring& alt_text) { + if (alt_text == alt_text_) + return; + + alt_text_ = alt_text; + if (!GetNativeControlHWND()) + return; + + RECT alt_text_bounds = GetAltTextBounds().ToRECT(); + InvalidateRect(GetNativeControlHWND(), &alt_text_bounds, FALSE); +} + void TableView::UpdateListViewCache0(int start, int length, bool add) { if (is_sorted()) { if (add) @@ -1492,6 +1522,23 @@ void TableView::UpdateContentOffset() { content_offset_ = origin.y + header_bounds.bottom - header_bounds.top; } +gfx::Rect TableView::GetAltTextBounds() { + static const int kXOffset = 16; + DCHECK(GetNativeControlHWND()); + RECT client_rect_rect; + GetClientRect(GetNativeControlHWND(), &client_rect_rect); + gfx::Rect client_rect(client_rect_rect); + gfx::Font font = GetAltTextFont(); + // Pad height by 2 for halo. + return gfx::Rect(kXOffset, content_offset(), client_rect.width() - kXOffset, + std::max(kImageSize, font.height() + 2)); +} + +gfx::Font TableView::GetAltTextFont() { + return ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont); +} + + // // TableSelectionIterator // diff --git a/views/controls/table/table_view.h b/views/controls/table/table_view.h index 282d590..0ed3396 100644 --- a/views/controls/table/table_view.h +++ b/views/controls/table/table_view.h @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -23,6 +23,10 @@ typedef struct tagNMLVCUSTOMDRAW NMLVCUSTOMDRAW; #include "views/controls/native_control.h" #endif // defined(OS_WIN) +namespace gfx { +class Font; +} + struct TableColumn; class TableModel; class SkBitmap; @@ -232,6 +236,10 @@ class TableView : public NativeControl, return view_to_model_.get() ? view_to_model_[view_index] : view_index; } + // Sets the text to display on top of the table. This is useful if the table + // is empty and you want to inform the user why. + void SetAltText(const std::wstring& alt_text); + protected: // Overriden to return the position of the first selected row. virtual gfx::Point GetKeyboardContextMenuLocation(); @@ -293,6 +301,9 @@ class TableView : public NativeControl, // content. int content_offset() const { return content_offset_; } + // Draws the alt_text_. Does nothing if there is no alt_text_. + void PaintAltText(); + // Size (width and height) of images. static const int kImageSize; @@ -398,6 +409,12 @@ class TableView : public NativeControl, // Updates content_offset_ from the position of the header. void UpdateContentOffset(); + // Returns the bounds of the alt text. + gfx::Rect GetAltTextBounds(); + + // Returns the font used for alt text. + gfx::Font GetAltTextFont(); + TableModel* model_; TableTypes table_type_; TableViewObserver* table_view_observer_; @@ -463,6 +480,8 @@ class TableView : public NativeControl, scoped_array<int> view_to_model_; scoped_array<int> model_to_view_; + std::wstring alt_text_; + DISALLOW_COPY_AND_ASSIGN(TableView); }; #endif // defined(OS_WIN) |