OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/view.h" | 5 #include "views/view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #ifndef NDEBUG | 8 #ifndef NDEBUG |
9 #include <iostream> | 9 #include <iostream> |
10 #endif | 10 #endif |
11 | 11 |
12 #include "app/drag_drop_types.h" | 12 #include "app/drag_drop_types.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
15 #include "base/scoped_handle.h" | 15 #include "base/scoped_handle.h" |
16 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
17 #include "gfx/canvas_skia.h" | 17 #include "gfx/canvas.h" |
18 #include "gfx/path.h" | 18 #include "gfx/path.h" |
19 #include "third_party/skia/include/core/SkShader.h" | 19 #include "third_party/skia/include/core/SkShader.h" |
20 #include "views/background.h" | 20 #include "views/background.h" |
21 #include "views/layout_manager.h" | 21 #include "views/layout_manager.h" |
22 #include "views/views_delegate.h" | 22 #include "views/views_delegate.h" |
23 #include "views/widget/root_view.h" | 23 #include "views/widget/root_view.h" |
24 #include "views/widget/tooltip_manager.h" | 24 #include "views/widget/tooltip_manager.h" |
25 #include "views/widget/widget.h" | 25 #include "views/widget/widget.h" |
26 #include "views/window/window.h" | 26 #include "views/window/window.h" |
27 | 27 |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 } | 371 } |
372 child->ProcessPaint(canvas); | 372 child->ProcessPaint(canvas); |
373 } | 373 } |
374 } | 374 } |
375 | 375 |
376 void View::ProcessPaint(gfx::Canvas* canvas) { | 376 void View::ProcessPaint(gfx::Canvas* canvas) { |
377 if (!IsVisible()) | 377 if (!IsVisible()) |
378 return; | 378 return; |
379 | 379 |
380 // We're going to modify the canvas, save it's state first. | 380 // We're going to modify the canvas, save it's state first. |
381 canvas->AsCanvasSkia()->save(); | 381 canvas->save(); |
382 | 382 |
383 // Paint this View and its children, setting the clip rect to the bounds | 383 // Paint this View and its children, setting the clip rect to the bounds |
384 // of this View and translating the origin to the local bounds' top left | 384 // of this View and translating the origin to the local bounds' top left |
385 // point. | 385 // point. |
386 // | 386 // |
387 // Note that the X (or left) position we pass to ClipRectInt takes into | 387 // Note that the X (or left) position we pass to ClipRectInt takes into |
388 // consideration whether or not the view uses a right-to-left layout so that | 388 // consideration whether or not the view uses a right-to-left layout so that |
389 // we paint our view in its mirrored position if need be. | 389 // we paint our view in its mirrored position if need be. |
390 if (canvas->ClipRectInt(MirroredX(), y(), width(), height())) { | 390 if (canvas->ClipRectInt(MirroredX(), y(), width(), height())) { |
391 // Non-empty clip, translate the graphics such that 0,0 corresponds to | 391 // Non-empty clip, translate the graphics such that 0,0 corresponds to |
392 // where this view is located (related to its parent). | 392 // where this view is located (related to its parent). |
393 canvas->TranslateInt(MirroredX(), y()); | 393 canvas->TranslateInt(MirroredX(), y()); |
394 | 394 |
395 // Save the state again, so that any changes don't effect PaintChildren. | 395 // Save the state again, so that any changes don't effect PaintChildren. |
396 canvas->AsCanvasSkia()->save(); | 396 canvas->save(); |
397 | 397 |
398 // If the View we are about to paint requested the canvas to be flipped, we | 398 // If the View we are about to paint requested the canvas to be flipped, we |
399 // should change the transform appropriately. | 399 // should change the transform appropriately. |
400 bool flip_canvas = FlipCanvasOnPaintForRTLUI(); | 400 bool flip_canvas = FlipCanvasOnPaintForRTLUI(); |
401 if (flip_canvas) { | 401 if (flip_canvas) { |
402 canvas->TranslateInt(width(), 0); | 402 canvas->TranslateInt(width(), 0); |
403 canvas->ScaleInt(-1, 1); | 403 canvas->ScaleInt(-1, 1); |
404 canvas->AsCanvasSkia()->save(); | 404 canvas->save(); |
405 } | 405 } |
406 | 406 |
407 Paint(canvas); | 407 Paint(canvas); |
408 | 408 |
409 // We must undo the canvas mirroring once the View is done painting so that | 409 // We must undo the canvas mirroring once the View is done painting so that |
410 // we don't pass the canvas with the mirrored transform to Views that | 410 // we don't pass the canvas with the mirrored transform to Views that |
411 // didn't request the canvas to be flipped. | 411 // didn't request the canvas to be flipped. |
412 if (flip_canvas) | 412 if (flip_canvas) |
413 canvas->AsCanvasSkia()->restore(); | 413 canvas->restore(); |
414 | 414 |
415 canvas->AsCanvasSkia()->restore(); | 415 canvas->restore(); |
416 PaintChildren(canvas); | 416 PaintChildren(canvas); |
417 } | 417 } |
418 | 418 |
419 // Restore the canvas's original transform. | 419 // Restore the canvas's original transform. |
420 canvas->AsCanvasSkia()->restore(); | 420 canvas->restore(); |
421 } | 421 } |
422 | 422 |
423 void View::PaintNow() { | 423 void View::PaintNow() { |
424 if (!IsVisible()) | 424 if (!IsVisible()) |
425 return; | 425 return; |
426 | 426 |
427 View* view = GetParent(); | 427 View* view = GetParent(); |
428 if (view) | 428 if (view) |
429 view->PaintNow(); | 429 view->PaintNow(); |
430 } | 430 } |
(...skipping 1077 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1508 possible_drag = false; | 1508 possible_drag = false; |
1509 start_pt = gfx::Point(); | 1509 start_pt = gfx::Point(); |
1510 } | 1510 } |
1511 | 1511 |
1512 void View::DragInfo::PossibleDrag(const gfx::Point& p) { | 1512 void View::DragInfo::PossibleDrag(const gfx::Point& p) { |
1513 possible_drag = true; | 1513 possible_drag = true; |
1514 start_pt = p; | 1514 start_pt = p; |
1515 } | 1515 } |
1516 | 1516 |
1517 } // namespace | 1517 } // namespace |
OLD | NEW |