1 // Copyright 2013 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.
5 #ifndef UI_MESSAGE_CENTER_VIEWS_PROPORTIONAL_IMAGE_VIEW_H_
6 #define UI_MESSAGE_CENTER_VIEWS_PROPORTIONAL_IMAGE_VIEW_H_
8 #include "ui/gfx/image/image_skia.h"
9 #include "ui/message_center/message_center_export.h"
10 #include "ui/views/view.h"
12 namespace message_center
{
14 // ProportionalImageViews scale and center their images while preserving their
15 // original proportions.
16 class MESSAGE_CENTER_EXPORT ProportionalImageView
: public views::View
{
18 // Internal class name.
19 static const char kViewClassName
[];
21 explicit ProportionalImageView(const gfx::Size
& view_size
);
22 ~ProportionalImageView() override
;
24 // |image| is scaled to fit within |view_size_| and |max_image_size| while
25 // maintaining its original aspect ratio. It is then centered within the view.
26 void SetImage(const gfx::ImageSkia
& image
,
27 const gfx::Size
& max_image_size
);
29 // Overridden from views::View:
30 gfx::Size
GetPreferredSize() const override
;
31 int GetHeightForWidth(int width
) const override
;
32 void OnPaint(gfx::Canvas
* canvas
) override
;
33 const char* GetClassName() const override
;
36 gfx::Size
GetImageDrawingSize();
38 gfx::ImageSkia image_
;
39 gfx::Size max_image_size_
;
42 DISALLOW_COPY_AND_ASSIGN(ProportionalImageView
);
45 } // namespace message_center
47 #endif // UI_MESSAGE_CENTER_VIEWS_PROPORTIONAL_IMAGE_VIEW_H_