• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2012 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 "chrome/browser/ui/tabs/tab_resources.h"
6 
7 #include "base/logging.h"
8 #include "ui/gfx/path.h"
9 
10 namespace {
11 
12 // Hit mask constants.
13 const SkScalar kTabCapWidth = 15;
14 const SkScalar kTabTopCurveWidth = 4;
15 const SkScalar kTabBottomCurveWidth = 3;
16 #if defined(TOOLKIT_VIEWS)
17 // Windows and Ash have shadows in the left, right and top parts of the tab.
18 const SkScalar kTabInset = 6;
19 const SkScalar kTabTop = 2;
20 #else
21 // Linux GTK and Mac don't have the shadows.
22 const SkScalar kTabInset = 0;
23 const SkScalar kTabTop = 0;
24 #endif
25 
26 }  // namespace
27 
28 // static
GetHitTestMask(int width,int height,bool include_top_shadow,gfx::Path * path)29 void TabResources::GetHitTestMask(int width,
30                                   int height,
31                                   bool include_top_shadow,
32                                   gfx::Path* path) {
33   DCHECK(path);
34 
35   SkScalar left = kTabInset;
36   SkScalar top = kTabTop;
37   SkScalar right = SkIntToScalar(width) - kTabInset;
38   SkScalar bottom = SkIntToScalar(height);
39 
40   // Start in the lower-left corner.
41   path->moveTo(left, bottom);
42 
43   // Left end cap.
44   path->lineTo(left + kTabBottomCurveWidth, bottom - kTabBottomCurveWidth);
45   path->lineTo(left + kTabCapWidth - kTabTopCurveWidth,
46                top + kTabTopCurveWidth);
47   path->lineTo(left + kTabCapWidth, top);
48 
49   // Extend over the top shadow area if we have one and the caller wants it.
50   if (kTabTop > 0 && include_top_shadow) {
51     path->lineTo(left + kTabCapWidth, 0);
52     path->lineTo(right - kTabCapWidth, 0);
53   }
54 
55   // Connect to the right cap.
56   path->lineTo(right - kTabCapWidth, top);
57 
58   // Right end cap.
59   path->lineTo(right - kTabCapWidth + kTabTopCurveWidth,
60                top + kTabTopCurveWidth);
61   path->lineTo(right - kTabBottomCurveWidth, bottom - kTabBottomCurveWidth);
62   path->lineTo(right, bottom);
63 
64   // Close out the path.
65   path->lineTo(left, bottom);
66   path->close();
67 }
68