Home | History | Annotate | Download | only in web
      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 
     35 using namespace WebCore;
     36 
     37 namespace blink {
     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 
     51     GraphicsContext context(canvas);
     52     context.setCertainlyOpaque(false);
     53     m_theme->paintScrollbarBackground(&context, m_scrollbar);
     54 }
     55 
     56 void WebScrollbarThemePainter::paintTrackBackground(WebCanvas* canvas, const WebRect& rect)
     57 {
     58     GraphicsContext context(canvas);
     59     context.setCertainlyOpaque(false);
     60     m_theme->paintTrackBackground(&context, m_scrollbar, IntRect(rect));
     61 }
     62 
     63 void WebScrollbarThemePainter::paintBackTrackPart(WebCanvas* canvas, const WebRect& rect)
     64 {
     65     GraphicsContext context(canvas);
     66     context.setCertainlyOpaque(false);
     67     m_theme->paintTrackPiece(&context, m_scrollbar, IntRect(rect), WebCore::BackTrackPart);
     68 }
     69 
     70 void WebScrollbarThemePainter::paintForwardTrackPart(WebCanvas* canvas, const WebRect& rect)
     71 {
     72     GraphicsContext context(canvas);
     73     context.setCertainlyOpaque(false);
     74     m_theme->paintTrackPiece(&context, m_scrollbar, IntRect(rect), WebCore::ForwardTrackPart);
     75 }
     76 
     77 void WebScrollbarThemePainter::paintBackButtonStart(WebCanvas* canvas, const WebRect& rect)
     78 {
     79     GraphicsContext context(canvas);
     80     context.setCertainlyOpaque(false);
     81     m_theme->paintButton(&context, m_scrollbar, IntRect(rect), WebCore::BackButtonStartPart);
     82 }
     83 
     84 void WebScrollbarThemePainter::paintBackButtonEnd(WebCanvas* canvas, const WebRect& rect)
     85 {
     86     GraphicsContext context(canvas);
     87     context.setCertainlyOpaque(false);
     88     m_theme->paintButton(&context, m_scrollbar, IntRect(rect), WebCore::BackButtonEndPart);
     89 }
     90 
     91 void WebScrollbarThemePainter::paintForwardButtonStart(WebCanvas* canvas, const WebRect& rect)
     92 {
     93     GraphicsContext context(canvas);
     94     context.setCertainlyOpaque(false);
     95     m_theme->paintButton(&context, m_scrollbar, IntRect(rect), WebCore::ForwardButtonStartPart);
     96 }
     97 
     98 void WebScrollbarThemePainter::paintForwardButtonEnd(WebCanvas* canvas, const WebRect& rect)
     99 {
    100     GraphicsContext context(canvas);
    101     context.setCertainlyOpaque(false);
    102     m_theme->paintButton(&context, m_scrollbar, IntRect(rect), WebCore::ForwardButtonEndPart);
    103 }
    104 
    105 void WebScrollbarThemePainter::paintTickmarks(WebCanvas* canvas, const WebRect& rect)
    106 {
    107     GraphicsContext context(canvas);
    108     context.setCertainlyOpaque(false);
    109     m_theme->paintTickmarks(&context, m_scrollbar, IntRect(rect));
    110 }
    111 
    112 void WebScrollbarThemePainter::paintThumb(WebCanvas* canvas, const WebRect& rect)
    113 {
    114     GraphicsContext context(canvas);
    115     context.setCertainlyOpaque(false);
    116     m_theme->paintThumb(&context, m_scrollbar, IntRect(rect));
    117 }
    118 
    119 WebScrollbarThemePainter::WebScrollbarThemePainter(WebCore::ScrollbarTheme* theme, WebCore::Scrollbar* scrollbar)
    120     : m_theme(theme)
    121     , m_scrollbar(scrollbar)
    122 {
    123 }
    124 
    125 } // namespace blink
    126