Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * |
| 8 | * 1. Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer in the |
| 12 | * documentation and/or other materials provided with the distribution. |
| 13 | * |
| 14 | * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY |
| 15 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 16 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 17 | * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
| 18 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 19 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 20 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 21 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | */ |
| 25 | |
| 26 | #include "config.h" |
| 27 | |
Torne (Richard Coles) | 5267f70 | 2013-06-11 10:57:24 +0100 | [diff] [blame] | 28 | #include "public/platform/WebScrollbarThemePainter.h" |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 29 | |
Torne (Richard Coles) | a854de0 | 2013-12-18 16:25:25 +0000 | [diff] [blame] | 30 | #include "platform/graphics/GraphicsContext.h" |
| 31 | #include "platform/scroll/Scrollbar.h" |
| 32 | #include "platform/scroll/ScrollbarTheme.h" |
Torne (Richard Coles) | 5267f70 | 2013-06-11 10:57:24 +0100 | [diff] [blame] | 33 | #include "public/platform/WebRect.h" |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 34 | |
| 35 | using namespace WebCore; |
| 36 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 37 | namespace blink { |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 38 | |
| 39 | void WebScrollbarThemePainter::assign(const WebScrollbarThemePainter& painter) |
| 40 | { |
| 41 | // This is a pointer to a static object, so no ownership transferral. |
| 42 | m_theme = painter.m_theme; |
| 43 | m_scrollbar = painter.m_scrollbar; |
| 44 | } |
| 45 | |
| 46 | void WebScrollbarThemePainter::paintScrollbarBackground(WebCanvas* canvas, const WebRect& rect) |
| 47 | { |
| 48 | SkRect clip = SkRect::MakeXYWH(rect.x, rect.y, rect.width, rect.height); |
| 49 | canvas->clipRect(clip); |
| 50 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 51 | GraphicsContext context(canvas); |
| 52 | context.setCertainlyOpaque(false); |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 53 | m_theme->paintScrollbarBackground(&context, m_scrollbar); |
| 54 | } |
| 55 | |
| 56 | void WebScrollbarThemePainter::paintTrackBackground(WebCanvas* canvas, const WebRect& rect) |
| 57 | { |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 58 | GraphicsContext context(canvas); |
| 59 | context.setCertainlyOpaque(false); |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 60 | m_theme->paintTrackBackground(&context, m_scrollbar, IntRect(rect)); |
| 61 | } |
| 62 | |
| 63 | void WebScrollbarThemePainter::paintBackTrackPart(WebCanvas* canvas, const WebRect& rect) |
| 64 | { |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 65 | GraphicsContext context(canvas); |
| 66 | context.setCertainlyOpaque(false); |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 67 | m_theme->paintTrackPiece(&context, m_scrollbar, IntRect(rect), WebCore::BackTrackPart); |
| 68 | } |
| 69 | |
| 70 | void WebScrollbarThemePainter::paintForwardTrackPart(WebCanvas* canvas, const WebRect& rect) |
| 71 | { |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 72 | GraphicsContext context(canvas); |
| 73 | context.setCertainlyOpaque(false); |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 74 | m_theme->paintTrackPiece(&context, m_scrollbar, IntRect(rect), WebCore::ForwardTrackPart); |
| 75 | } |
| 76 | |
| 77 | void WebScrollbarThemePainter::paintBackButtonStart(WebCanvas* canvas, const WebRect& rect) |
| 78 | { |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 79 | GraphicsContext context(canvas); |
| 80 | context.setCertainlyOpaque(false); |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 81 | m_theme->paintButton(&context, m_scrollbar, IntRect(rect), WebCore::BackButtonStartPart); |
| 82 | } |
| 83 | |
| 84 | void WebScrollbarThemePainter::paintBackButtonEnd(WebCanvas* canvas, const WebRect& rect) |
| 85 | { |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 86 | GraphicsContext context(canvas); |
| 87 | context.setCertainlyOpaque(false); |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 88 | m_theme->paintButton(&context, m_scrollbar, IntRect(rect), WebCore::BackButtonEndPart); |
| 89 | } |
| 90 | |
| 91 | void WebScrollbarThemePainter::paintForwardButtonStart(WebCanvas* canvas, const WebRect& rect) |
| 92 | { |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 93 | GraphicsContext context(canvas); |
| 94 | context.setCertainlyOpaque(false); |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 95 | m_theme->paintButton(&context, m_scrollbar, IntRect(rect), WebCore::ForwardButtonStartPart); |
| 96 | } |
| 97 | |
| 98 | void WebScrollbarThemePainter::paintForwardButtonEnd(WebCanvas* canvas, const WebRect& rect) |
| 99 | { |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 100 | GraphicsContext context(canvas); |
| 101 | context.setCertainlyOpaque(false); |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 102 | m_theme->paintButton(&context, m_scrollbar, IntRect(rect), WebCore::ForwardButtonEndPart); |
| 103 | } |
| 104 | |
| 105 | void WebScrollbarThemePainter::paintTickmarks(WebCanvas* canvas, const WebRect& rect) |
| 106 | { |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 107 | GraphicsContext context(canvas); |
| 108 | context.setCertainlyOpaque(false); |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 109 | m_theme->paintTickmarks(&context, m_scrollbar, IntRect(rect)); |
| 110 | } |
| 111 | |
| 112 | void WebScrollbarThemePainter::paintThumb(WebCanvas* canvas, const WebRect& rect) |
| 113 | { |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 114 | GraphicsContext context(canvas); |
| 115 | context.setCertainlyOpaque(false); |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 116 | m_theme->paintThumb(&context, m_scrollbar, IntRect(rect)); |
| 117 | } |
| 118 | |
Ben Murdoch | 3c9e4ae | 2013-08-12 14:20:44 +0100 | [diff] [blame] | 119 | WebScrollbarThemePainter::WebScrollbarThemePainter(WebCore::ScrollbarTheme* theme, WebCore::Scrollbar* scrollbar) |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 120 | : m_theme(theme) |
| 121 | , m_scrollbar(scrollbar) |
| 122 | { |
| 123 | } |
| 124 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 125 | } // namespace blink |