OLD | NEW |
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 Loading... |
800 // Set the # of rows. | 800 // Set the # of rows. |
801 if (model_) | 801 if (model_) |
802 UpdateListViewCache(0, model_->RowCount(), true); | 802 UpdateListViewCache(0, model_->RowCount(), true); |
803 | 803 |
804 if (table_type_ == ICON_AND_TEXT) { | 804 if (table_type_ == ICON_AND_TEXT) { |
805 HIMAGELIST image_list = | 805 HIMAGELIST image_list = |
806 ImageList_Create(kImageSize, kImageSize, ILC_COLOR32, 2, 2); | 806 ImageList_Create(kImageSize, kImageSize, ILC_COLOR32, 2, 2); |
807 // We create 2 phony images because we are going to switch images at every | 807 // We create 2 phony images because we are going to switch images at every |
808 // refresh in order to force a refresh of the icon area (somehow the clip | 808 // refresh in order to force a refresh of the icon area (somehow the clip |
809 // rect does not include the icon). | 809 // rect does not include the icon). |
810 gfx::CanvasSkia canvas(kImageSize, kImageSize, false); | 810 gfx::CanvasSkia canvas; |
| 811 canvas.Init(kImageSize, kImageSize, false); |
811 // Make the background completely transparent. | 812 // Make the background completely transparent. |
812 canvas.drawColor(SK_ColorBLACK, SkXfermode::kClear_Mode); | 813 canvas.skia_canvas()->drawColor(SK_ColorBLACK, SkXfermode::kClear_Mode); |
813 HICON empty_icon = | 814 HICON empty_icon = |
814 IconUtil::CreateHICONFromSkBitmap(canvas.ExtractBitmap()); | 815 IconUtil::CreateHICONFromSkBitmap(canvas.ExtractBitmap()); |
815 ImageList_AddIcon(image_list, empty_icon); | 816 ImageList_AddIcon(image_list, empty_icon); |
816 ImageList_AddIcon(image_list, empty_icon); | 817 ImageList_AddIcon(image_list, empty_icon); |
817 DeleteObject(empty_icon); | 818 DeleteObject(empty_icon); |
818 ListView_SetImageList(list_view_, image_list, LVSIL_SMALL); | 819 ListView_SetImageList(list_view_, image_list, LVSIL_SMALL); |
819 } | 820 } |
820 | 821 |
821 if (!resizable_columns_) { | 822 if (!resizable_columns_) { |
822 // To disable the resizing of columns we'll filter the events happening on | 823 // To disable the resizing of columns we'll filter the events happening on |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1146 list_view_, static_cast<int>(i - visible_columns_.begin())); | 1147 list_view_, static_cast<int>(i - visible_columns_.begin())); |
1147 } | 1148 } |
1148 | 1149 |
1149 void TableView::PaintAltText() { | 1150 void TableView::PaintAltText() { |
1150 if (alt_text_.empty()) | 1151 if (alt_text_.empty()) |
1151 return; | 1152 return; |
1152 | 1153 |
1153 HDC dc = GetDC(GetNativeControlHWND()); | 1154 HDC dc = GetDC(GetNativeControlHWND()); |
1154 gfx::Font font = GetAltTextFont(); | 1155 gfx::Font font = GetAltTextFont(); |
1155 gfx::Rect bounds = GetAltTextBounds(); | 1156 gfx::Rect bounds = GetAltTextBounds(); |
1156 gfx::CanvasSkia canvas(bounds.width(), bounds.height(), false); | 1157 gfx::CanvasSkia canvas; |
| 1158 canvas.Init(bounds.width(), bounds.height(), false); |
1157 // Pad by 1 for halo. | 1159 // Pad by 1 for halo. |
1158 canvas.DrawStringWithHalo(alt_text_, font, SK_ColorDKGRAY, SK_ColorWHITE, 1, | 1160 canvas.DrawStringWithHalo(alt_text_, font, SK_ColorDKGRAY, SK_ColorWHITE, 1, |
1159 1, bounds.width() - 2, bounds.height() - 2, | 1161 1, bounds.width() - 2, bounds.height() - 2, |
1160 gfx::CanvasSkia::DefaultCanvasTextAlignment()); | 1162 gfx::CanvasSkia::DefaultCanvasTextAlignment()); |
1161 canvas.getTopPlatformDevice().drawToHDC(dc, bounds.x(), bounds.y(), NULL); | 1163 canvas.BlitToNativeContext(gfx::Rect(bounds.size()), bounds.origin(), dc); |
1162 ReleaseDC(GetNativeControlHWND(), dc); | 1164 ReleaseDC(GetNativeControlHWND(), dc); |
1163 } | 1165 } |
1164 | 1166 |
1165 LRESULT TableView::OnCustomDraw(NMLVCUSTOMDRAW* draw_info) { | 1167 LRESULT TableView::OnCustomDraw(NMLVCUSTOMDRAW* draw_info) { |
1166 switch (draw_info->nmcd.dwDrawStage) { | 1168 switch (draw_info->nmcd.dwDrawStage) { |
1167 case CDDS_PREPAINT: { | 1169 case CDDS_PREPAINT: { |
1168 return CDRF_NOTIFYITEMDRAW; | 1170 return CDRF_NOTIFYITEMDRAW; |
1169 } | 1171 } |
1170 case CDDS_ITEMPREPAINT: { | 1172 case CDDS_ITEMPREPAINT: { |
1171 // The list-view is about to paint an item, tell it we want to | 1173 // The list-view is about to paint an item, tell it we want to |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1229 RECT icon_rect, client_rect; | 1231 RECT icon_rect, client_rect; |
1230 if (ListView_GetItemRect(list_view_, view_index, &icon_rect, | 1232 if (ListView_GetItemRect(list_view_, view_index, &icon_rect, |
1231 LVIR_ICON) && | 1233 LVIR_ICON) && |
1232 GetClientRect(list_view_, &client_rect)) { | 1234 GetClientRect(list_view_, &client_rect)) { |
1233 RECT intersection; | 1235 RECT intersection; |
1234 // Client rect includes the header but we need to make sure we don't | 1236 // Client rect includes the header but we need to make sure we don't |
1235 // paint into it. | 1237 // paint into it. |
1236 client_rect.top += content_offset_; | 1238 client_rect.top += content_offset_; |
1237 // Make sure the region need to paint is visible. | 1239 // Make sure the region need to paint is visible. |
1238 if (IntersectRect(&intersection, &icon_rect, &client_rect)) { | 1240 if (IntersectRect(&intersection, &icon_rect, &client_rect)) { |
1239 gfx::CanvasSkia canvas(icon_rect.right - icon_rect.left, | 1241 gfx::CanvasSkia canvas; |
1240 icon_rect.bottom - icon_rect.top, false); | 1242 canvas.Init(icon_rect.right - icon_rect.left, |
| 1243 icon_rect.bottom - icon_rect.top, |
| 1244 false); |
1241 | 1245 |
1242 // It seems the state in nmcd.uItemState is not correct. | 1246 // It seems the state in nmcd.uItemState is not correct. |
1243 // We'll retrieve it explicitly. | 1247 // We'll retrieve it explicitly. |
1244 int selected = ListView_GetItemState( | 1248 int selected = ListView_GetItemState( |
1245 list_view_, view_index, LVIS_SELECTED | LVIS_DROPHILITED); | 1249 list_view_, view_index, LVIS_SELECTED | LVIS_DROPHILITED); |
1246 bool drop_highlight = ((selected & LVIS_DROPHILITED) != 0); | 1250 bool drop_highlight = ((selected & LVIS_DROPHILITED) != 0); |
1247 int bg_color_index; | 1251 int bg_color_index; |
1248 if (!IsEnabled()) | 1252 if (!IsEnabled()) |
1249 bg_color_index = COLOR_3DFACE; | 1253 bg_color_index = COLOR_3DFACE; |
1250 else if (drop_highlight) | 1254 else if (drop_highlight) |
1251 bg_color_index = COLOR_HIGHLIGHT; | 1255 bg_color_index = COLOR_HIGHLIGHT; |
1252 else if (selected) | 1256 else if (selected) |
1253 bg_color_index = HasFocus() ? COLOR_HIGHLIGHT : COLOR_3DFACE; | 1257 bg_color_index = HasFocus() ? COLOR_HIGHLIGHT : COLOR_3DFACE; |
1254 else | 1258 else |
1255 bg_color_index = COLOR_WINDOW; | 1259 bg_color_index = COLOR_WINDOW; |
1256 // NOTE: This may be invoked without the ListView filling in the | 1260 // NOTE: This may be invoked without the ListView filling in the |
1257 // background (or rather windows paints background, then invokes | 1261 // background (or rather windows paints background, then invokes |
1258 // this twice). As such, we always fill in the background. | 1262 // this twice). As such, we always fill in the background. |
1259 canvas.drawColor( | 1263 canvas.skia_canvas()->drawColor( |
1260 skia::COLORREFToSkColor(GetSysColor(bg_color_index)), | 1264 skia::COLORREFToSkColor(GetSysColor(bg_color_index)), |
1261 SkXfermode::kSrc_Mode); | 1265 SkXfermode::kSrc_Mode); |
1262 // + 1 for padding (we declared the image as 18x18 in the list- | 1266 // + 1 for padding (we declared the image as 18x18 in the list- |
1263 // view when they are 16x16 so we get an extra pixel of padding). | 1267 // view when they are 16x16 so we get an extra pixel of padding). |
1264 canvas.DrawBitmapInt(image, 0, 0, | 1268 canvas.DrawBitmapInt(image, 0, 0, |
1265 image.width(), image.height(), | 1269 image.width(), image.height(), |
1266 1, 1, kFaviconSize, kFaviconSize, true); | 1270 1, 1, kFaviconSize, kFaviconSize, true); |
1267 | 1271 |
1268 // Only paint the visible region of the icon. | 1272 // Only paint the visible region of the icon. |
1269 RECT to_draw = { intersection.left - icon_rect.left, | 1273 RECT to_draw = { intersection.left - icon_rect.left, |
1270 intersection.top - icon_rect.top, | 1274 intersection.top - icon_rect.top, |
1271 0, 0 }; | 1275 0, 0 }; |
1272 to_draw.right = to_draw.left + | 1276 to_draw.right = to_draw.left + |
1273 (intersection.right - intersection.left); | 1277 (intersection.right - intersection.left); |
1274 to_draw.bottom = to_draw.top + | 1278 to_draw.bottom = to_draw.top + |
1275 (intersection.bottom - intersection.top); | 1279 (intersection.bottom - intersection.top); |
1276 canvas.getTopPlatformDevice().drawToHDC(draw_info->nmcd.hdc, | 1280 canvas.BlitToNativeContext( |
1277 intersection.left, | 1281 gfx::Rect(to_draw), |
1278 intersection.top, | 1282 gfx::Point(intersection.left, intersection.top), |
1279 &to_draw); | 1283 draw_info->nmcd.hdc); |
1280 r = CDRF_SKIPDEFAULT; | 1284 r = CDRF_SKIPDEFAULT; |
1281 } | 1285 } |
1282 } | 1286 } |
1283 } | 1287 } |
1284 } | 1288 } |
1285 if (ImplementPostPaint()) { | 1289 if (ImplementPostPaint()) { |
1286 RECT cell_rect; | 1290 RECT cell_rect; |
1287 if (ListView_GetItemRect(list_view_, view_index, &cell_rect, | 1291 if (ListView_GetItemRect(list_view_, view_index, &cell_rect, |
1288 LVIR_BOUNDS)) { | 1292 LVIR_BOUNDS)) { |
1289 PostPaint(model_index, 0, false, gfx::Rect(cell_rect), | 1293 PostPaint(model_index, 0, false, gfx::Rect(cell_rect), |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1636 } | 1640 } |
1637 | 1641 |
1638 void TableSelectionIterator::UpdateModelIndexFromViewIndex() { | 1642 void TableSelectionIterator::UpdateModelIndexFromViewIndex() { |
1639 if (view_index_ == -1) | 1643 if (view_index_ == -1) |
1640 model_index_ = -1; | 1644 model_index_ = -1; |
1641 else | 1645 else |
1642 model_index_ = table_view_->ViewToModel(view_index_); | 1646 model_index_ = table_view_->ViewToModel(view_index_); |
1643 } | 1647 } |
1644 | 1648 |
1645 } // namespace views | 1649 } // namespace views |
OLD | NEW |