OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ui/views/corewm/cursor_height_provider_win.h" | 5 #include "ui/views/corewm/cursor_height_provider_win.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <algorithm> |
8 #include <map> | 9 #include <map> |
9 | 10 |
10 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
11 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
12 #include "base/win/scoped_hdc.h" | 13 #include "base/win/scoped_hdc.h" |
13 | 14 |
14 namespace { | 15 namespace { |
15 typedef scoped_ptr<uint32_t> PixelData; | 16 typedef scoped_ptr<uint32_t> PixelData; |
16 typedef std::map<HCURSOR, int> HeightStorage; | 17 typedef std::map<HCURSOR, int> HeightStorage; |
17 | 18 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 else | 99 else |
99 last_byte_mask = 0; | 100 last_byte_mask = 0; |
100 | 101 |
101 const uint32_t row_size = | 102 const uint32_t row_size = |
102 (bitmap_info.bmiHeader.biWidth + kBitsPeruint32 - 1) / kBitsPeruint32; | 103 (bitmap_info.bmiHeader.biWidth + kBitsPeruint32 - 1) / kBitsPeruint32; |
103 PixelData data(GetBitmapData(icon.hbmMask, bitmap_info, hdc)); | 104 PixelData data(GetBitmapData(icon.hbmMask, bitmap_info, hdc)); |
104 if (data == NULL) | 105 if (data == NULL) |
105 return kDefaultHeight; | 106 return kDefaultHeight; |
106 | 107 |
107 const int cursor_height = GetSystemMetrics(SM_CYCURSOR); | 108 const int cursor_height = GetSystemMetrics(SM_CYCURSOR); |
108 int i = bitmap_info.bmiHeader.biHeight - cursor_height; | 109 // Crash data seems to indicate cursor_height may be bigger than the bitmap. |
| 110 int i = std::max(0, static_cast<int>(bitmap_info.bmiHeader.biHeight) - |
| 111 cursor_height); |
109 for (; i < bitmap_info.bmiHeader.biHeight; ++i) { | 112 for (; i < bitmap_info.bmiHeader.biHeight; ++i) { |
110 if (!IsRowTransparent(data, row_size, last_byte_mask, i)) { | 113 if (!IsRowTransparent(data, row_size, last_byte_mask, i)) { |
111 i--; | 114 i--; |
112 break; | 115 break; |
113 } | 116 } |
114 } | 117 } |
115 return bitmap_info.bmiHeader.biHeight - i - icon.yHotspot; | 118 return bitmap_info.bmiHeader.biHeight - i - icon.yHotspot; |
116 } | 119 } |
117 | 120 |
118 } // namespace | 121 } // namespace |
(...skipping 15 matching lines...) Expand all Loading... |
134 return cached_height->second; | 137 return cached_height->second; |
135 | 138 |
136 const int height = CalculateCursorHeight(cursor.hCursor); | 139 const int height = CalculateCursorHeight(cursor.hCursor); |
137 (*cached_heights)[cursor.hCursor] = height; | 140 (*cached_heights)[cursor.hCursor] = height; |
138 | 141 |
139 return height; | 142 return height; |
140 } | 143 } |
141 | 144 |
142 } // namespace corewm | 145 } // namespace corewm |
143 } // namespace views | 146 } // namespace views |
OLD | NEW |