Home | History | Annotate | Download | only in style
      1 // Copyright 2014 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include "config.h"
      6 #include "core/rendering/style/BorderEdge.h"
      7 
      8 namespace blink {
      9 
     10 BorderEdge::BorderEdge(int edgeWidth, const Color& edgeColor, EBorderStyle edgeStyle, bool edgeIsTransparent, bool edgeIsPresent)
     11     : width(edgeWidth)
     12     , color(edgeColor)
     13     , isTransparent(edgeIsTransparent)
     14     , isPresent(edgeIsPresent)
     15     , style(edgeStyle)
     16 {
     17     if (style == DOUBLE && edgeWidth < 3)
     18         style = SOLID;
     19 }
     20 
     21 BorderEdge::BorderEdge()
     22     : width(0)
     23     , isTransparent(false)
     24     , isPresent(false)
     25     , style(BHIDDEN)
     26 {
     27 }
     28 
     29 bool BorderEdge::hasVisibleColorAndStyle() const
     30 {
     31     return style > BHIDDEN && !isTransparent;
     32 }
     33 
     34 bool BorderEdge::shouldRender() const { return isPresent && width && hasVisibleColorAndStyle(); }
     35 bool BorderEdge::presentButInvisible() const { return usedWidth() && !hasVisibleColorAndStyle(); }
     36 bool BorderEdge::obscuresBackgroundEdge(float scale) const
     37 {
     38     if (!isPresent || isTransparent || (width * scale) < 2 || color.hasAlpha() || style == BHIDDEN)
     39         return false;
     40 
     41     if (style == DOTTED || style == DASHED)
     42         return false;
     43 
     44     if (style == DOUBLE)
     45         return width >= 5 * scale; // The outer band needs to be >= 2px wide at unit scale.
     46 
     47     return true;
     48 }
     49 bool BorderEdge::obscuresBackground() const
     50 {
     51     if (!isPresent || isTransparent || color.hasAlpha() || style == BHIDDEN)
     52         return false;
     53 
     54     if (style == DOTTED || style == DASHED || style == DOUBLE)
     55         return false;
     56 
     57     return true;
     58 }
     59 
     60 int BorderEdge::usedWidth() const
     61 {
     62     return isPresent ? width : 0;
     63 }
     64 
     65 void BorderEdge::getDoubleBorderStripeWidths(int& outerWidth, int& innerWidth) const
     66 {
     67     int fullWidth = usedWidth();
     68     outerWidth = fullWidth / 3;
     69     innerWidth = fullWidth * 2 / 3;
     70 
     71     // We need certain integer rounding results
     72     if (fullWidth % 3 == 2)
     73         outerWidth += 1;
     74 
     75     if (fullWidth % 3 == 1)
     76         innerWidth += 1;
     77 }
     78 
     79 bool BorderEdge::sharesColorWith(const BorderEdge& other) const
     80 {
     81     return color == other.color;
     82 }
     83 
     84 } // namespace blink
     85