summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/cocoa/location_bar/bubble_decoration.h
blob: 623b95a4f5764aac7e83232b6245594d60be3ac8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_UI_COCOA_LOCATION_BAR_BUBBLE_DECORATION_H_
#define CHROME_BROWSER_UI_COCOA_LOCATION_BAR_BUBBLE_DECORATION_H_

#import <Cocoa/Cocoa.h>

#include "base/gtest_prod_util.h"
#include "base/mac/scoped_nsobject.h"
#include "base/macros.h"
#include "chrome/browser/ui/cocoa/location_bar/location_bar_decoration.h"
#import "ui/base/cocoa/appkit_utils.h"

// Draws an outlined rounded rect, with an optional image to the left
// and an optional text label to the right.

class BubbleDecoration : public LocationBarDecoration {
 public:
  BubbleDecoration();
  ~BubbleDecoration() override;

  // Setup the drawing parameters.
  NSImage* GetImage();
  virtual NSColor* GetBackgroundBorderColor() = 0;
  void SetImage(NSImage* image);
  void SetLabel(NSString* label);
  void SetTextColor(NSColor* text_color);
  virtual ui::NinePartImageIds GetBubbleImageIds() = 0;

  // Implement |LocationBarDecoration|.
  void DrawInFrame(NSRect frame, NSView* control_view) override;
  void DrawWithBackgroundInFrame(NSRect background_frame,
                                 NSRect frame,
                                 NSView* control_view) override;
  CGFloat GetWidthForSpace(CGFloat width) override;

 protected:
  // Helper returning bubble width for the given |image| and |label|
  // assuming |font_| (for sizing text).  Arguments can be nil.
  CGFloat GetWidthForImageAndLabel(NSImage* image, NSString* label);

  // Helper to return where the image is drawn, for subclasses to drag
  // from.  |frame| is the decoration's frame in the containing cell.
  NSRect GetImageRectInFrame(NSRect frame);

 private:
  friend class SelectedKeywordDecorationTest;
  FRIEND_TEST_ALL_PREFIXES(SelectedKeywordDecorationTest,
                           UsesPartialKeywordIfNarrow);

  // Image drawn in the left side of the bubble.
  base::scoped_nsobject<NSImage> image_;

  // Label to draw to right of image.  Can be |nil|.
  base::scoped_nsobject<NSString> label_;

  // Contains attribute for drawing |label_|.
  base::scoped_nsobject<NSMutableDictionary> attributes_;

  DISALLOW_COPY_AND_ASSIGN(BubbleDecoration);
};

#endif  // CHROME_BROWSER_UI_COCOA_LOCATION_BAR_BUBBLE_DECORATION_H_