blob: 02430f3bc138e2dcb3a3e73518a9140dfaeb6759 [file] [log] [blame]
// Copyright 2013 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.
#include "base/macros.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/message_center/message_center_export.h"
#include "ui/views/view.h"
namespace message_center {
// ProportionalImageViews scale and center their images while preserving their
// original proportions.
class MESSAGE_CENTER_EXPORT ProportionalImageView : public views::View {
// Internal class name.
static const char kViewClassName[];
explicit ProportionalImageView(const gfx::Size& view_size);
~ProportionalImageView() override;
// |image| is scaled to fit within |view_size_| and |max_image_size| while
// maintaining its original aspect ratio. It is then centered within the view.
void SetImage(const gfx::ImageSkia& image,
const gfx::Size& max_image_size);
// Overridden from views::View:
gfx::Size GetPreferredSize() const override;
int GetHeightForWidth(int width) const override;
void OnPaint(gfx::Canvas* canvas) override;
const char* GetClassName() const override;
gfx::Size GetImageDrawingSize();
gfx::ImageSkia image_;
gfx::Size max_image_size_;
gfx::Size view_size_;
} // namespace message_center