Home | History | Annotate | Download | only in chromium
      1 /*
      2  * Copyright (C) 2011 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 #include "core/platform/chromium/ScrollbarThemeChromiumOverlay.h"
     28 
     29 #include "core/platform/PlatformMouseEvent.h"
     30 #include "core/platform/Scrollbar.h"
     31 #include "core/platform/graphics/GraphicsContext.h"
     32 #include "core/platform/graphics/transforms/TransformationMatrix.h"
     33 
     34 #include <algorithm>
     35 
     36 using namespace std;
     37 
     38 namespace WebCore {
     39 
     40 static const int scrollbarWidth = 3;
     41 static const int scrollbarMargin = 4;
     42 
     43 int ScrollbarThemeChromiumOverlay::scrollbarThickness(ScrollbarControlSize controlSize)
     44 {
     45     return scrollbarWidth + scrollbarMargin;
     46 }
     47 
     48 bool ScrollbarThemeChromiumOverlay::usesOverlayScrollbars() const
     49 {
     50     return true;
     51 }
     52 
     53 int ScrollbarThemeChromiumOverlay::thumbPosition(ScrollbarThemeClient* scrollbar)
     54 {
     55     if (!scrollbar->totalSize())
     56         return 0;
     57 
     58     int trackLen = trackLength(scrollbar);
     59     float proportion = static_cast<float>(scrollbar->currentPos()) / scrollbar->totalSize();
     60     return round(proportion * trackLen);
     61 }
     62 
     63 int ScrollbarThemeChromiumOverlay::thumbLength(ScrollbarThemeClient* scrollbar)
     64 {
     65     int trackLen = trackLength(scrollbar);
     66 
     67     if (!scrollbar->totalSize())
     68         return trackLen;
     69 
     70     float proportion = (float)scrollbar->visibleSize() / scrollbar->totalSize();
     71     int length = round(proportion * trackLen);
     72     length = min(max(length, minimumThumbLength(scrollbar)), trackLen);
     73     return length;
     74 }
     75 
     76 bool ScrollbarThemeChromiumOverlay::hasThumb(ScrollbarThemeClient* scrollbar)
     77 {
     78     return true;
     79 }
     80 
     81 IntRect ScrollbarThemeChromiumOverlay::backButtonRect(ScrollbarThemeClient*, ScrollbarPart, bool)
     82 {
     83     return IntRect();
     84 }
     85 
     86 IntRect ScrollbarThemeChromiumOverlay::forwardButtonRect(ScrollbarThemeClient*, ScrollbarPart, bool)
     87 {
     88     return IntRect();
     89 }
     90 
     91 IntRect ScrollbarThemeChromiumOverlay::trackRect(ScrollbarThemeClient* scrollbar, bool)
     92 {
     93     IntRect rect = scrollbar->frameRect();
     94     if (scrollbar->orientation() == HorizontalScrollbar)
     95         rect.inflateX(-scrollbarMargin);
     96     else
     97         rect.inflateY(-scrollbarMargin);
     98     return rect;
     99 }
    100 
    101 void ScrollbarThemeChromiumOverlay::paintThumb(GraphicsContext* context, ScrollbarThemeClient* scrollbar, const IntRect& rect)
    102 {
    103     IntRect thumbRect = rect;
    104     if (scrollbar->orientation() == HorizontalScrollbar)
    105         thumbRect.setHeight(thumbRect.height() - scrollbarMargin);
    106     else
    107         thumbRect.setWidth(thumbRect.width() - scrollbarMargin);
    108     context->fillRect(thumbRect, Color(128, 128, 128, 128));
    109 }
    110 
    111 } // namespace WebCore
    112