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
28#include "public/platform/WebScrollbarThemePainter.h"
29
30#include "platform/graphics/GraphicsContext.h"
31#include "platform/scroll/Scrollbar.h"
32#include "platform/scroll/ScrollbarTheme.h"
33#include "public/platform/WebRect.h"
34
35namespace blink {
36
37void WebScrollbarThemePainter::assign(const WebScrollbarThemePainter& painter)
38{
39    // This is a pointer to a static object, so no ownership transferral.
40    m_theme = painter.m_theme;
41    m_scrollbar = painter.m_scrollbar;
42}
43
44void WebScrollbarThemePainter::paintScrollbarBackground(WebCanvas* canvas, const WebRect& rect)
45{
46    SkRect clip = SkRect::MakeXYWH(rect.x, rect.y, rect.width, rect.height);
47    canvas->clipRect(clip);
48
49    GraphicsContext context(canvas);
50    context.setCertainlyOpaque(false);
51    m_theme->paintScrollbarBackground(&context, m_scrollbar);
52}
53
54void WebScrollbarThemePainter::paintTrackBackground(WebCanvas* canvas, const WebRect& rect)
55{
56    GraphicsContext context(canvas);
57    context.setCertainlyOpaque(false);
58    m_theme->paintTrackBackground(&context, m_scrollbar, IntRect(rect));
59}
60
61void WebScrollbarThemePainter::paintBackTrackPart(WebCanvas* canvas, const WebRect& rect)
62{
63    GraphicsContext context(canvas);
64    context.setCertainlyOpaque(false);
65    m_theme->paintTrackPiece(&context, m_scrollbar, IntRect(rect), BackTrackPart);
66}
67
68void WebScrollbarThemePainter::paintForwardTrackPart(WebCanvas* canvas, const WebRect& rect)
69{
70    GraphicsContext context(canvas);
71    context.setCertainlyOpaque(false);
72    m_theme->paintTrackPiece(&context, m_scrollbar, IntRect(rect), ForwardTrackPart);
73}
74
75void WebScrollbarThemePainter::paintBackButtonStart(WebCanvas* canvas, const WebRect& rect)
76{
77    GraphicsContext context(canvas);
78    context.setCertainlyOpaque(false);
79    m_theme->paintButton(&context, m_scrollbar, IntRect(rect), BackButtonStartPart);
80}
81
82void WebScrollbarThemePainter::paintBackButtonEnd(WebCanvas* canvas, const WebRect& rect)
83{
84    GraphicsContext context(canvas);
85    context.setCertainlyOpaque(false);
86    m_theme->paintButton(&context, m_scrollbar, IntRect(rect), BackButtonEndPart);
87}
88
89void WebScrollbarThemePainter::paintForwardButtonStart(WebCanvas* canvas, const WebRect& rect)
90{
91    GraphicsContext context(canvas);
92    context.setCertainlyOpaque(false);
93    m_theme->paintButton(&context, m_scrollbar, IntRect(rect), ForwardButtonStartPart);
94}
95
96void WebScrollbarThemePainter::paintForwardButtonEnd(WebCanvas* canvas, const WebRect& rect)
97{
98    GraphicsContext context(canvas);
99    context.setCertainlyOpaque(false);
100    m_theme->paintButton(&context, m_scrollbar, IntRect(rect), ForwardButtonEndPart);
101}
102
103void WebScrollbarThemePainter::paintTickmarks(WebCanvas* canvas, const WebRect& rect)
104{
105    GraphicsContext context(canvas);
106    context.setCertainlyOpaque(false);
107    m_theme->paintTickmarks(&context, m_scrollbar, IntRect(rect));
108}
109
110void WebScrollbarThemePainter::paintThumb(WebCanvas* canvas, const WebRect& rect)
111{
112    GraphicsContext context(canvas);
113    context.setCertainlyOpaque(false);
114    m_theme->paintThumb(&context, m_scrollbar, IntRect(rect));
115}
116
117WebScrollbarThemePainter::WebScrollbarThemePainter(ScrollbarTheme* theme, Scrollbar* scrollbar)
118    : m_theme(theme)
119    , m_scrollbar(scrollbar)
120{
121}
122
123} // namespace blink
124