~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Source/WebCore/platform/chromium/ScrollbarThemeChromium.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
 
3
 * Copyright (C) 2008, 2009 Google Inc.
 
4
 *
 
5
 * Redistribution and use in source and binary forms, with or without
 
6
 * modification, are permitted provided that the following conditions
 
7
 * are met:
 
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 INC. ``AS IS'' AND ANY
 
15
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 
16
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 
17
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
 
18
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 
19
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 
20
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 
21
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 
22
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 
23
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 
24
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
25
 */
 
26
 
 
27
#include "config.h"
 
28
#include "ScrollbarThemeChromium.h"
 
29
 
 
30
#include "PlatformMouseEvent.h"
 
31
#include "ScrollableArea.h"
 
32
#include "Scrollbar.h"
 
33
#include "ScrollbarThemeComposite.h"
 
34
 
 
35
// -----------------------------------------------------------------------------
 
36
// This file contains scrollbar theme code that is cross platform. Additional
 
37
// members of ScrollbarThemeChromium can be found in the platform specific files
 
38
// -----------------------------------------------------------------------------
 
39
 
 
40
namespace WebCore {
 
41
 
 
42
bool ScrollbarThemeChromium::hasThumb(ScrollbarThemeClient* scrollbar)
 
43
{
 
44
    // This method is just called as a paint-time optimization to see if
 
45
    // painting the thumb can be skipped.  We don't have to be exact here.
 
46
    return thumbLength(scrollbar) > 0;
 
47
}
 
48
 
 
49
IntRect ScrollbarThemeChromium::backButtonRect(ScrollbarThemeClient* scrollbar, ScrollbarPart part, bool)
 
50
{
 
51
    // Windows and Linux just have single arrows.
 
52
    if (part == BackButtonEndPart)
 
53
        return IntRect();
 
54
 
 
55
    IntSize size = buttonSize(scrollbar);
 
56
    return IntRect(scrollbar->x(), scrollbar->y(), size.width(), size.height());
 
57
}
 
58
 
 
59
IntRect ScrollbarThemeChromium::forwardButtonRect(ScrollbarThemeClient* scrollbar, ScrollbarPart part, bool)
 
60
{
 
61
    // Windows and Linux just have single arrows.
 
62
    if (part == ForwardButtonStartPart)
 
63
        return IntRect();
 
64
 
 
65
    IntSize size = buttonSize(scrollbar);
 
66
    int x, y;
 
67
    if (scrollbar->orientation() == HorizontalScrollbar) {
 
68
        x = scrollbar->x() + scrollbar->width() - size.width();
 
69
        y = scrollbar->y();
 
70
    } else {
 
71
        x = scrollbar->x();
 
72
        y = scrollbar->y() + scrollbar->height() - size.height();
 
73
    }
 
74
    return IntRect(x, y, size.width(), size.height());
 
75
}
 
76
 
 
77
IntRect ScrollbarThemeChromium::trackRect(ScrollbarThemeClient* scrollbar, bool)
 
78
{
 
79
    IntSize bs = buttonSize(scrollbar);
 
80
    // The buttons at the top and bottom of the scrollbar are square, so the
 
81
    // thickness of the scrollbar is also their height.
 
82
    int thickness = scrollbarThickness(scrollbar->controlSize());
 
83
    if (scrollbar->orientation() == HorizontalScrollbar) {
 
84
        // Once the scrollbar becomes smaller than the natural size of the
 
85
        // two buttons, the track disappears.
 
86
        if (scrollbar->width() < 2 * thickness)
 
87
            return IntRect();
 
88
        return IntRect(scrollbar->x() + bs.width(), scrollbar->y(), scrollbar->width() - 2 * bs.width(), thickness);
 
89
    }
 
90
    if (scrollbar->height() < 2 * thickness)
 
91
        return IntRect();
 
92
    return IntRect(scrollbar->x(), scrollbar->y() + bs.height(), thickness, scrollbar->height() - 2 * bs.height());
 
93
}
 
94
 
 
95
void ScrollbarThemeChromium::paintTrackBackground(GraphicsContext* context, ScrollbarThemeClient* scrollbar, const IntRect& rect)
 
96
{
 
97
    // Just assume a forward track part.  We only paint the track as a single piece when there is no thumb.
 
98
    if (!hasThumb(scrollbar))
 
99
        paintTrackPiece(context, scrollbar, rect, ForwardTrackPart);
 
100
}
 
101
 
 
102
void ScrollbarThemeChromium::paintTickmarks(GraphicsContext* context, ScrollbarThemeClient* scrollbar, const IntRect& rect)
 
103
{
 
104
    if (scrollbar->orientation() != VerticalScrollbar)
 
105
        return;
 
106
 
 
107
    if (rect.height() <= 0 || rect.width() <= 0)
 
108
        return;  // nothing to draw on.
 
109
 
 
110
    // Get the tickmarks for the frameview.
 
111
    Vector<IntRect> tickmarks;
 
112
    scrollbar->getTickmarks(tickmarks);
 
113
    if (!tickmarks.size())
 
114
        return;
 
115
 
 
116
    GraphicsContextStateSaver stateSaver(*context);
 
117
    context->setShouldAntialias(false);
 
118
 
 
119
    for (Vector<IntRect>::const_iterator i = tickmarks.begin(); i != tickmarks.end(); ++i) {
 
120
        // Calculate how far down (in %) the tick-mark should appear.
 
121
        const float percent = static_cast<float>(i->y()) / scrollbar->totalSize();
 
122
 
 
123
        // Calculate how far down (in pixels) the tick-mark should appear.
 
124
        const int yPos = rect.y() + (rect.height() * percent);
 
125
 
 
126
        context->setFillColor(Color(0xCC, 0xAA, 0x00, 0xFF), ColorSpaceDeviceRGB);
 
127
        FloatRect tickRect(rect.x(), yPos, rect.width(), 3);
 
128
        context->fillRect(tickRect);
 
129
 
 
130
        context->setFillColor(Color(0xFF, 0xDD, 0x00, 0xFF), ColorSpaceDeviceRGB);
 
131
        FloatRect tickStroke(rect.x(), yPos + 1, rect.width(), 1);
 
132
        context->fillRect(tickStroke);
 
133
    }
 
134
}
 
135
 
 
136
} // namespace WebCore