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 "chrome/browser/autocomplete/autocomplete_edit_view_win.h" | 5 #include "chrome/browser/autocomplete/autocomplete_edit_view_win.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <locale> | 8 #include <locale> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 2274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2285 | 2285 |
2286 // Create a paint context for drawing the antialiased stroke. | 2286 // Create a paint context for drawing the antialiased stroke. |
2287 SkPaint paint; | 2287 SkPaint paint; |
2288 paint.setAntiAlias(true); | 2288 paint.setAntiAlias(true); |
2289 paint.setStrokeWidth(kStrokeWidthPixels); | 2289 paint.setStrokeWidth(kStrokeWidthPixels); |
2290 paint.setStrokeCap(SkPaint::kRound_Cap); | 2290 paint.setStrokeCap(SkPaint::kRound_Cap); |
2291 | 2291 |
2292 // Create a canvas as large as |scheme_rect| to do our drawing, and initialize | 2292 // Create a canvas as large as |scheme_rect| to do our drawing, and initialize |
2293 // it to fully transparent so any antialiasing will look nice when painted | 2293 // it to fully transparent so any antialiasing will look nice when painted |
2294 // atop the edit. | 2294 // atop the edit. |
2295 gfx::CanvasSkia canvas(scheme_rect.Width(), scheme_rect.Height(), false); | 2295 gfx::CanvasSkia canvas; |
2296 canvas.getDevice()->accessBitmap(true).eraseARGB(0, 0, 0, 0); | 2296 canvas.Init(scheme_rect.Width(), scheme_rect.Height(), false); |
| 2297 canvas.skia_canvas()->getDevice()->accessBitmap(true).eraseARGB(0, 0, 0, 0); |
2297 | 2298 |
2298 // Calculate the start and end of the stroke, which are just the lower left | 2299 // Calculate the start and end of the stroke, which are just the lower left |
2299 // and upper right corners of the canvas, inset by the radius of the endcap | 2300 // and upper right corners of the canvas, inset by the radius of the endcap |
2300 // so we don't clip the endcap off. | 2301 // so we don't clip the endcap off. |
2301 const SkScalar kEndCapRadiusPixels = kStrokeWidthPixels / SkIntToScalar(2); | 2302 const SkScalar kEndCapRadiusPixels = kStrokeWidthPixels / SkIntToScalar(2); |
2302 const SkPoint start_point = { | 2303 const SkPoint start_point = { |
2303 kEndCapRadiusPixels, | 2304 kEndCapRadiusPixels, |
2304 SkIntToScalar(scheme_rect.Height()) - kEndCapRadiusPixels }; | 2305 SkIntToScalar(scheme_rect.Height()) - kEndCapRadiusPixels }; |
2305 const SkPoint end_point = { | 2306 const SkPoint end_point = { |
2306 SkIntToScalar(scheme_rect.Width()) - kEndCapRadiusPixels, | 2307 SkIntToScalar(scheme_rect.Width()) - kEndCapRadiusPixels, |
2307 kEndCapRadiusPixels }; | 2308 kEndCapRadiusPixels }; |
2308 | 2309 |
2309 // Calculate the selection rectangle in canvas coordinates, which we'll use | 2310 // Calculate the selection rectangle in canvas coordinates, which we'll use |
2310 // to clip the stroke so we can draw the unselected and selected portions. | 2311 // to clip the stroke so we can draw the unselected and selected portions. |
2311 CHARRANGE sel; | 2312 CHARRANGE sel; |
2312 GetSel(sel); | 2313 GetSel(sel); |
2313 const SkRect selection_rect = { | 2314 const SkRect selection_rect = { |
2314 SkIntToScalar(PosFromChar(sel.cpMin).x - scheme_rect.left), | 2315 SkIntToScalar(PosFromChar(sel.cpMin).x - scheme_rect.left), |
2315 SkIntToScalar(0), | 2316 SkIntToScalar(0), |
2316 SkIntToScalar(PosFromChar(sel.cpMax).x - scheme_rect.left), | 2317 SkIntToScalar(PosFromChar(sel.cpMax).x - scheme_rect.left), |
2317 SkIntToScalar(scheme_rect.Height()) }; | 2318 SkIntToScalar(scheme_rect.Height()) }; |
2318 | 2319 |
2319 // Draw the unselected portion of the stroke. | 2320 // Draw the unselected portion of the stroke. |
2320 canvas.save(); | 2321 canvas.Save(); |
2321 if (selection_rect.isEmpty() || | 2322 if (selection_rect.isEmpty() || |
2322 canvas.clipRect(selection_rect, SkRegion::kDifference_Op)) { | 2323 canvas.skia_canvas()->clipRect(selection_rect, |
| 2324 SkRegion::kDifference_Op)) { |
2323 paint.setColor(LocationBarView::GetColor(security_level_, | 2325 paint.setColor(LocationBarView::GetColor(security_level_, |
2324 LocationBarView::SECURITY_TEXT)); | 2326 LocationBarView::SECURITY_TEXT)); |
2325 canvas.drawLine(start_point.fX, start_point.fY, | 2327 canvas.skia_canvas()->drawLine( |
2326 end_point.fX, end_point.fY, paint); | 2328 start_point.fX, start_point.fY, end_point.fX, end_point.fY, paint); |
2327 } | 2329 } |
2328 canvas.restore(); | 2330 canvas.Restore(); |
2329 | 2331 |
2330 // Draw the selected portion of the stroke. | 2332 // Draw the selected portion of the stroke. |
2331 if (!selection_rect.isEmpty() && canvas.clipRect(selection_rect)) { | 2333 if (!selection_rect.isEmpty() && |
| 2334 canvas.skia_canvas()->clipRect(selection_rect)) { |
2332 paint.setColor(LocationBarView::GetColor(security_level_, | 2335 paint.setColor(LocationBarView::GetColor(security_level_, |
2333 LocationBarView::SELECTED_TEXT)); | 2336 LocationBarView::SELECTED_TEXT)); |
2334 canvas.drawLine(start_point.fX, start_point.fY, | 2337 canvas.skia_canvas()->drawLine( |
2335 end_point.fX, end_point.fY, paint); | 2338 start_point.fX, start_point.fY, end_point.fX, end_point.fY, paint); |
2336 } | 2339 } |
2337 | 2340 |
2338 // Now copy what we drew to the target HDC. | 2341 // Now copy what we drew to the target HDC. |
2339 canvas.getTopPlatformDevice().drawToHDC(hdc, | 2342 gfx::Point dst_origin( |
2340 scheme_rect.left + canvas_paint_clip_rect.left - canvas_clip_rect.left, | 2343 scheme_rect.left + canvas_paint_clip_rect.left - canvas_clip_rect.left, |
2341 std::max(scheme_rect.top, client_rect.top) + canvas_paint_clip_rect.top - | 2344 std::max(scheme_rect.top, client_rect.top) + |
2342 canvas_clip_rect.top, &canvas_paint_clip_rect); | 2345 canvas_paint_clip_rect.top - canvas_clip_rect.top); |
| 2346 canvas.BlitToNativeContext(gfx::Rect(canvas_paint_clip_rect), |
| 2347 dst_origin, hdc); |
2343 } | 2348 } |
2344 | 2349 |
2345 void AutocompleteEditViewWin::DrawDropHighlight(HDC hdc, | 2350 void AutocompleteEditViewWin::DrawDropHighlight(HDC hdc, |
2346 const CRect& client_rect, | 2351 const CRect& client_rect, |
2347 const CRect& paint_clip_rect) { | 2352 const CRect& paint_clip_rect) { |
2348 DCHECK_NE(-1, drop_highlight_position_); | 2353 DCHECK_NE(-1, drop_highlight_position_); |
2349 | 2354 |
2350 const int highlight_y = client_rect.top + font_y_adjustment_; | 2355 const int highlight_y = client_rect.top + font_y_adjustment_; |
2351 const int highlight_x = PosFromChar(drop_highlight_position_).x - 1; | 2356 const int highlight_x = PosFromChar(drop_highlight_position_).x - 1; |
2352 const CRect highlight_rect(highlight_x, | 2357 const CRect highlight_rect(highlight_x, |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2621 // PosFromChar(i) might return 0 when i is greater than 1. | 2626 // PosFromChar(i) might return 0 when i is greater than 1. |
2622 return font_.GetStringWidth(text) + GetHorizontalMargin(); | 2627 return font_.GetStringWidth(text) + GetHorizontalMargin(); |
2623 } | 2628 } |
2624 | 2629 |
2625 bool AutocompleteEditViewWin::IsCaretAtEnd() const { | 2630 bool AutocompleteEditViewWin::IsCaretAtEnd() const { |
2626 long length = GetTextLength(); | 2631 long length = GetTextLength(); |
2627 CHARRANGE sel; | 2632 CHARRANGE sel; |
2628 GetSelection(sel); | 2633 GetSelection(sel); |
2629 return sel.cpMin == sel.cpMax && sel.cpMin == length; | 2634 return sel.cpMin == sel.cpMax && sel.cpMin == length; |
2630 } | 2635 } |
OLD | NEW |