Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(299)

Side by Side Diff: views/controls/table/table_view.cc

Issue 8122013: Allow CanvasSkia to bind to an existing SkCanvas. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: 1 more fix Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "views/controls/table/table_view.h" 5 #include "views/controls/table/table_view.h"
6 6
7 #include <commctrl.h> 7 #include <commctrl.h>
8 #include <windowsx.h> 8 #include <windowsx.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 789 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 UpdateListViewCache(0, model_->RowCount(), true); 800 UpdateListViewCache(0, model_->RowCount(), true);
801 801
802 if (table_type_ == ICON_AND_TEXT) { 802 if (table_type_ == ICON_AND_TEXT) {
803 HIMAGELIST image_list = 803 HIMAGELIST image_list =
804 ImageList_Create(kImageSize, kImageSize, ILC_COLOR32, 2, 2); 804 ImageList_Create(kImageSize, kImageSize, ILC_COLOR32, 2, 2);
805 // We create 2 phony images because we are going to switch images at every 805 // We create 2 phony images because we are going to switch images at every
806 // refresh in order to force a refresh of the icon area (somehow the clip 806 // refresh in order to force a refresh of the icon area (somehow the clip
807 // rect does not include the icon). 807 // rect does not include the icon).
808 gfx::CanvasSkia canvas(kImageSize, kImageSize, false); 808 gfx::CanvasSkia canvas(kImageSize, kImageSize, false);
809 // Make the background completely transparent. 809 // Make the background completely transparent.
810 canvas.drawColor(SK_ColorBLACK, SkXfermode::kClear_Mode); 810 canvas.sk_canvas()->drawColor(SK_ColorBLACK, SkXfermode::kClear_Mode);
811 { 811 {
812 base::win::ScopedHICON empty_icon( 812 base::win::ScopedHICON empty_icon(
813 IconUtil::CreateHICONFromSkBitmap(canvas.ExtractBitmap())); 813 IconUtil::CreateHICONFromSkBitmap(canvas.ExtractBitmap()));
814 ImageList_AddIcon(image_list, empty_icon); 814 ImageList_AddIcon(image_list, empty_icon);
815 ImageList_AddIcon(image_list, empty_icon); 815 ImageList_AddIcon(image_list, empty_icon);
816 } 816 }
817 ListView_SetImageList(list_view_, image_list, LVSIL_SMALL); 817 ListView_SetImageList(list_view_, image_list, LVSIL_SMALL);
818 } 818 }
819 819
820 if (!resizable_columns_) { 820 if (!resizable_columns_) {
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
1150 return; 1150 return;
1151 1151
1152 HDC dc = GetDC(GetNativeControlHWND()); 1152 HDC dc = GetDC(GetNativeControlHWND());
1153 gfx::Font font = GetAltTextFont(); 1153 gfx::Font font = GetAltTextFont();
1154 gfx::Rect bounds = GetAltTextBounds(); 1154 gfx::Rect bounds = GetAltTextBounds();
1155 gfx::CanvasSkia canvas(bounds.width(), bounds.height(), false); 1155 gfx::CanvasSkia canvas(bounds.width(), bounds.height(), false);
1156 // Pad by 1 for halo. 1156 // Pad by 1 for halo.
1157 canvas.DrawStringWithHalo(alt_text_, font, SK_ColorDKGRAY, SK_ColorWHITE, 1, 1157 canvas.DrawStringWithHalo(alt_text_, font, SK_ColorDKGRAY, SK_ColorWHITE, 1,
1158 1, bounds.width() - 2, bounds.height() - 2, 1158 1, bounds.width() - 2, bounds.height() - 2,
1159 gfx::CanvasSkia::DefaultCanvasTextAlignment()); 1159 gfx::CanvasSkia::DefaultCanvasTextAlignment());
1160 skia::DrawToNativeContext(&canvas, dc, bounds.x(), bounds.y(), NULL); 1160 skia::DrawToNativeContext(
1161 canvas.sk_canvas(), dc, bounds.x(), bounds.y(), NULL);
1161 ReleaseDC(GetNativeControlHWND(), dc); 1162 ReleaseDC(GetNativeControlHWND(), dc);
1162 } 1163 }
1163 1164
1164 LRESULT TableView::OnCustomDraw(NMLVCUSTOMDRAW* draw_info) { 1165 LRESULT TableView::OnCustomDraw(NMLVCUSTOMDRAW* draw_info) {
1165 switch (draw_info->nmcd.dwDrawStage) { 1166 switch (draw_info->nmcd.dwDrawStage) {
1166 case CDDS_PREPAINT: { 1167 case CDDS_PREPAINT: {
1167 return CDRF_NOTIFYITEMDRAW; 1168 return CDRF_NOTIFYITEMDRAW;
1168 } 1169 }
1169 case CDDS_ITEMPREPAINT: { 1170 case CDDS_ITEMPREPAINT: {
1170 // The list-view is about to paint an item, tell it we want to 1171 // The list-view is about to paint an item, tell it we want to
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
1248 bg_color_index = COLOR_3DFACE; 1249 bg_color_index = COLOR_3DFACE;
1249 else if (drop_highlight) 1250 else if (drop_highlight)
1250 bg_color_index = COLOR_HIGHLIGHT; 1251 bg_color_index = COLOR_HIGHLIGHT;
1251 else if (selected) 1252 else if (selected)
1252 bg_color_index = HasFocus() ? COLOR_HIGHLIGHT : COLOR_3DFACE; 1253 bg_color_index = HasFocus() ? COLOR_HIGHLIGHT : COLOR_3DFACE;
1253 else 1254 else
1254 bg_color_index = COLOR_WINDOW; 1255 bg_color_index = COLOR_WINDOW;
1255 // NOTE: This may be invoked without the ListView filling in the 1256 // NOTE: This may be invoked without the ListView filling in the
1256 // background (or rather windows paints background, then invokes 1257 // background (or rather windows paints background, then invokes
1257 // this twice). As such, we always fill in the background. 1258 // this twice). As such, we always fill in the background.
1258 canvas.drawColor( 1259 canvas.sk_canvas()->drawColor(
1259 skia::COLORREFToSkColor(GetSysColor(bg_color_index)), 1260 skia::COLORREFToSkColor(GetSysColor(bg_color_index)),
1260 SkXfermode::kSrc_Mode); 1261 SkXfermode::kSrc_Mode);
1261 // + 1 for padding (we declared the image as 18x18 in the list- 1262 // + 1 for padding (we declared the image as 18x18 in the list-
1262 // view when they are 16x16 so we get an extra pixel of padding). 1263 // view when they are 16x16 so we get an extra pixel of padding).
1263 canvas.DrawBitmapInt(image, 0, 0, 1264 canvas.DrawBitmapInt(image, 0, 0,
1264 image.width(), image.height(), 1265 image.width(), image.height(),
1265 1, 1, 1266 1, 1,
1266 gfx::kFaviconSize, gfx::kFaviconSize, true); 1267 gfx::kFaviconSize, gfx::kFaviconSize, true);
1267 1268
1268 // Only paint the visible region of the icon. 1269 // Only paint the visible region of the icon.
1269 RECT to_draw = { intersection.left - icon_rect.left, 1270 RECT to_draw = { intersection.left - icon_rect.left,
1270 intersection.top - icon_rect.top, 1271 intersection.top - icon_rect.top,
1271 0, 0 }; 1272 0, 0 };
1272 to_draw.right = to_draw.left + 1273 to_draw.right = to_draw.left +
1273 (intersection.right - intersection.left); 1274 (intersection.right - intersection.left);
1274 to_draw.bottom = to_draw.top + 1275 to_draw.bottom = to_draw.top +
1275 (intersection.bottom - intersection.top); 1276 (intersection.bottom - intersection.top);
1276 skia::DrawToNativeContext(&canvas, draw_info->nmcd.hdc, 1277 skia::DrawToNativeContext(canvas.sk_canvas(), draw_info->nmcd.hdc,
1277 intersection.left, intersection.top, 1278 intersection.left, intersection.top,
1278 &to_draw); 1279 &to_draw);
1279 r = CDRF_SKIPDEFAULT; 1280 r = CDRF_SKIPDEFAULT;
1280 } 1281 }
1281 } 1282 }
1282 } 1283 }
1283 } 1284 }
1284 if (ImplementPostPaint()) { 1285 if (ImplementPostPaint()) {
1285 RECT cell_rect; 1286 RECT cell_rect;
1286 if (ListView_GetItemRect(list_view_, view_index, &cell_rect, 1287 if (ListView_GetItemRect(list_view_, view_index, &cell_rect,
1287 LVIR_BOUNDS)) { 1288 LVIR_BOUNDS)) {
1288 PostPaint(model_index, 0, false, gfx::Rect(cell_rect), 1289 PostPaint(model_index, 0, false, gfx::Rect(cell_rect),
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
1635 } 1636 }
1636 1637
1637 void TableSelectionIterator::UpdateModelIndexFromViewIndex() { 1638 void TableSelectionIterator::UpdateModelIndexFromViewIndex() {
1638 if (view_index_ == -1) 1639 if (view_index_ == -1)
1639 model_index_ = -1; 1640 model_index_ = -1;
1640 else 1641 else
1641 model_index_ = table_view_->ViewToModel(view_index_); 1642 model_index_ = table_view_->ViewToModel(view_index_);
1642 } 1643 }
1643 1644
1644 } // namespace views 1645 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698