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/ui/views/omnibox/omnibox_view_win.h" | 5 #include "chrome/browser/ui/views/omnibox/omnibox_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 2257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2268 // Create a paint context for drawing the antialiased stroke. | 2268 // Create a paint context for drawing the antialiased stroke. |
2269 SkPaint paint; | 2269 SkPaint paint; |
2270 paint.setAntiAlias(true); | 2270 paint.setAntiAlias(true); |
2271 paint.setStrokeWidth(kStrokeWidthPixels); | 2271 paint.setStrokeWidth(kStrokeWidthPixels); |
2272 paint.setStrokeCap(SkPaint::kRound_Cap); | 2272 paint.setStrokeCap(SkPaint::kRound_Cap); |
2273 | 2273 |
2274 // Create a canvas as large as |scheme_rect| to do our drawing, and initialize | 2274 // Create a canvas as large as |scheme_rect| to do our drawing, and initialize |
2275 // it to fully transparent so any antialiasing will look nice when painted | 2275 // it to fully transparent so any antialiasing will look nice when painted |
2276 // atop the edit. | 2276 // atop the edit. |
2277 gfx::CanvasSkia canvas(scheme_rect.Width(), scheme_rect.Height(), false); | 2277 gfx::CanvasSkia canvas(scheme_rect.Width(), scheme_rect.Height(), false); |
2278 canvas.getDevice()->accessBitmap(true).eraseARGB(0, 0, 0, 0); | 2278 SkCanvas* sk_canvas = canvas.sk_canvas(); |
| 2279 sk_canvas->getDevice()->accessBitmap(true).eraseARGB(0, 0, 0, 0); |
2279 | 2280 |
2280 // Calculate the start and end of the stroke, which are just the lower left | 2281 // Calculate the start and end of the stroke, which are just the lower left |
2281 // and upper right corners of the canvas, inset by the radius of the endcap | 2282 // and upper right corners of the canvas, inset by the radius of the endcap |
2282 // so we don't clip the endcap off. | 2283 // so we don't clip the endcap off. |
2283 const SkScalar kEndCapRadiusPixels = kStrokeWidthPixels / SkIntToScalar(2); | 2284 const SkScalar kEndCapRadiusPixels = kStrokeWidthPixels / SkIntToScalar(2); |
2284 const SkPoint start_point = { | 2285 const SkPoint start_point = { |
2285 kEndCapRadiusPixels, | 2286 kEndCapRadiusPixels, |
2286 SkIntToScalar(scheme_rect.Height()) - kEndCapRadiusPixels }; | 2287 SkIntToScalar(scheme_rect.Height()) - kEndCapRadiusPixels }; |
2287 const SkPoint end_point = { | 2288 const SkPoint end_point = { |
2288 SkIntToScalar(scheme_rect.Width()) - kEndCapRadiusPixels, | 2289 SkIntToScalar(scheme_rect.Width()) - kEndCapRadiusPixels, |
2289 kEndCapRadiusPixels }; | 2290 kEndCapRadiusPixels }; |
2290 | 2291 |
2291 // Calculate the selection rectangle in canvas coordinates, which we'll use | 2292 // Calculate the selection rectangle in canvas coordinates, which we'll use |
2292 // to clip the stroke so we can draw the unselected and selected portions. | 2293 // to clip the stroke so we can draw the unselected and selected portions. |
2293 CHARRANGE sel; | 2294 CHARRANGE sel; |
2294 GetSel(sel); | 2295 GetSel(sel); |
2295 const SkRect selection_rect = { | 2296 const SkRect selection_rect = { |
2296 SkIntToScalar(PosFromChar(sel.cpMin).x - scheme_rect.left), | 2297 SkIntToScalar(PosFromChar(sel.cpMin).x - scheme_rect.left), |
2297 SkIntToScalar(0), | 2298 SkIntToScalar(0), |
2298 SkIntToScalar(PosFromChar(sel.cpMax).x - scheme_rect.left), | 2299 SkIntToScalar(PosFromChar(sel.cpMax).x - scheme_rect.left), |
2299 SkIntToScalar(scheme_rect.Height()) }; | 2300 SkIntToScalar(scheme_rect.Height()) }; |
2300 | 2301 |
2301 // Draw the unselected portion of the stroke. | 2302 // Draw the unselected portion of the stroke. |
2302 canvas.save(); | 2303 sk_canvas->save(); |
2303 if (selection_rect.isEmpty() || | 2304 if (selection_rect.isEmpty() || |
2304 canvas.clipRect(selection_rect, SkRegion::kDifference_Op)) { | 2305 sk_canvas->clipRect(selection_rect, SkRegion::kDifference_Op)) { |
2305 paint.setColor(LocationBarView::GetColor(security_level_, | 2306 paint.setColor(LocationBarView::GetColor(security_level_, |
2306 LocationBarView::SECURITY_TEXT)); | 2307 LocationBarView::SECURITY_TEXT)); |
2307 canvas.drawLine(start_point.fX, start_point.fY, | 2308 sk_canvas->drawLine(start_point.fX, start_point.fY, |
2308 end_point.fX, end_point.fY, paint); | 2309 end_point.fX, end_point.fY, paint); |
2309 } | 2310 } |
2310 canvas.restore(); | 2311 sk_canvas->restore(); |
2311 | 2312 |
2312 // Draw the selected portion of the stroke. | 2313 // Draw the selected portion of the stroke. |
2313 if (!selection_rect.isEmpty() && canvas.clipRect(selection_rect)) { | 2314 if (!selection_rect.isEmpty() && sk_canvas->clipRect(selection_rect)) { |
2314 paint.setColor(LocationBarView::GetColor(security_level_, | 2315 paint.setColor(LocationBarView::GetColor(security_level_, |
2315 LocationBarView::SELECTED_TEXT)); | 2316 LocationBarView::SELECTED_TEXT)); |
2316 canvas.drawLine(start_point.fX, start_point.fY, | 2317 sk_canvas->drawLine(start_point.fX, start_point.fY, |
2317 end_point.fX, end_point.fY, paint); | 2318 end_point.fX, end_point.fY, paint); |
2318 } | 2319 } |
2319 | 2320 |
2320 // Now copy what we drew to the target HDC. | 2321 // Now copy what we drew to the target HDC. |
2321 skia::DrawToNativeContext(&canvas, hdc, | 2322 skia::DrawToNativeContext(sk_canvas, hdc, |
2322 scheme_rect.left + canvas_paint_clip_rect.left - canvas_clip_rect.left, | 2323 scheme_rect.left + canvas_paint_clip_rect.left - canvas_clip_rect.left, |
2323 std::max(scheme_rect.top, client_rect.top) + canvas_paint_clip_rect.top - | 2324 std::max(scheme_rect.top, client_rect.top) + canvas_paint_clip_rect.top - |
2324 canvas_clip_rect.top, &canvas_paint_clip_rect); | 2325 canvas_clip_rect.top, &canvas_paint_clip_rect); |
2325 } | 2326 } |
2326 | 2327 |
2327 void OmniboxViewWin::DrawDropHighlight(HDC hdc, | 2328 void OmniboxViewWin::DrawDropHighlight(HDC hdc, |
2328 const CRect& client_rect, | 2329 const CRect& client_rect, |
2329 const CRect& paint_clip_rect) { | 2330 const CRect& paint_clip_rect) { |
2330 DCHECK_NE(-1, drop_highlight_position_); | 2331 DCHECK_NE(-1, drop_highlight_position_); |
2331 | 2332 |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2599 // PosFromChar(i) might return 0 when i is greater than 1. | 2600 // PosFromChar(i) might return 0 when i is greater than 1. |
2600 return font_.GetStringWidth(text) + GetHorizontalMargin(); | 2601 return font_.GetStringWidth(text) + GetHorizontalMargin(); |
2601 } | 2602 } |
2602 | 2603 |
2603 bool OmniboxViewWin::IsCaretAtEnd() const { | 2604 bool OmniboxViewWin::IsCaretAtEnd() const { |
2604 long length = GetTextLength(); | 2605 long length = GetTextLength(); |
2605 CHARRANGE sel; | 2606 CHARRANGE sel; |
2606 GetSelection(sel); | 2607 GetSelection(sel); |
2607 return sel.cpMin == sel.cpMax && sel.cpMin == length; | 2608 return sel.cpMin == sel.cpMax && sel.cpMin == length; |
2608 } | 2609 } |
OLD | NEW |