blob: 8d4712a013612dc23db03a4c204729cf77b09bbc [file] [log] [blame]
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +00001/*
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)5267f702013-06-11 10:57:24 +010028#include "public/platform/WebScrollbarThemePainter.h"
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +000029
Torne (Richard Coles)a854de02013-12-18 16:25:25 +000030#include "platform/graphics/GraphicsContext.h"
31#include "platform/scroll/Scrollbar.h"
32#include "platform/scroll/ScrollbarTheme.h"
Torne (Richard Coles)5267f702013-06-11 10:57:24 +010033#include "public/platform/WebRect.h"
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +000034
35using namespace WebCore;
36
Torne (Richard Coles)51b29062013-11-28 11:56:03 +000037namespace blink {
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +000038
39void 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
46void 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)53e740f2013-05-09 18:38:43 +010051 GraphicsContext context(canvas);
52 context.setCertainlyOpaque(false);
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +000053 m_theme->paintScrollbarBackground(&context, m_scrollbar);
54}
55
56void WebScrollbarThemePainter::paintTrackBackground(WebCanvas* canvas, const WebRect& rect)
57{
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010058 GraphicsContext context(canvas);
59 context.setCertainlyOpaque(false);
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +000060 m_theme->paintTrackBackground(&context, m_scrollbar, IntRect(rect));
61}
62
63void WebScrollbarThemePainter::paintBackTrackPart(WebCanvas* canvas, const WebRect& rect)
64{
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010065 GraphicsContext context(canvas);
66 context.setCertainlyOpaque(false);
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +000067 m_theme->paintTrackPiece(&context, m_scrollbar, IntRect(rect), WebCore::BackTrackPart);
68}
69
70void WebScrollbarThemePainter::paintForwardTrackPart(WebCanvas* canvas, const WebRect& rect)
71{
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010072 GraphicsContext context(canvas);
73 context.setCertainlyOpaque(false);
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +000074 m_theme->paintTrackPiece(&context, m_scrollbar, IntRect(rect), WebCore::ForwardTrackPart);
75}
76
77void WebScrollbarThemePainter::paintBackButtonStart(WebCanvas* canvas, const WebRect& rect)
78{
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010079 GraphicsContext context(canvas);
80 context.setCertainlyOpaque(false);
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +000081 m_theme->paintButton(&context, m_scrollbar, IntRect(rect), WebCore::BackButtonStartPart);
82}
83
84void WebScrollbarThemePainter::paintBackButtonEnd(WebCanvas* canvas, const WebRect& rect)
85{
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010086 GraphicsContext context(canvas);
87 context.setCertainlyOpaque(false);
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +000088 m_theme->paintButton(&context, m_scrollbar, IntRect(rect), WebCore::BackButtonEndPart);
89}
90
91void WebScrollbarThemePainter::paintForwardButtonStart(WebCanvas* canvas, const WebRect& rect)
92{
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010093 GraphicsContext context(canvas);
94 context.setCertainlyOpaque(false);
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +000095 m_theme->paintButton(&context, m_scrollbar, IntRect(rect), WebCore::ForwardButtonStartPart);
96}
97
98void WebScrollbarThemePainter::paintForwardButtonEnd(WebCanvas* canvas, const WebRect& rect)
99{
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100100 GraphicsContext context(canvas);
101 context.setCertainlyOpaque(false);
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000102 m_theme->paintButton(&context, m_scrollbar, IntRect(rect), WebCore::ForwardButtonEndPart);
103}
104
105void WebScrollbarThemePainter::paintTickmarks(WebCanvas* canvas, const WebRect& rect)
106{
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100107 GraphicsContext context(canvas);
108 context.setCertainlyOpaque(false);
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000109 m_theme->paintTickmarks(&context, m_scrollbar, IntRect(rect));
110}
111
112void WebScrollbarThemePainter::paintThumb(WebCanvas* canvas, const WebRect& rect)
113{
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100114 GraphicsContext context(canvas);
115 context.setCertainlyOpaque(false);
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000116 m_theme->paintThumb(&context, m_scrollbar, IntRect(rect));
117}
118
Ben Murdoch3c9e4ae2013-08-12 14:20:44 +0100119WebScrollbarThemePainter::WebScrollbarThemePainter(WebCore::ScrollbarTheme* theme, WebCore::Scrollbar* scrollbar)
Torne (Richard Coles)5c87bf82012-11-14 11:46:17 +0000120 : m_theme(theme)
121 , m_scrollbar(scrollbar)
122{
123}
124
Torne (Richard Coles)51b29062013-11-28 11:56:03 +0000125} // namespace blink