15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// found in the LICENSE file.
45d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
55d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#ifndef UI_GFX_GEOMETRY_SIZE_F_H_
65d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#define UI_GFX_GEOMETRY_SIZE_F_H_
75d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
8116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include <iosfwd>
95d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include <string>
105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/compiler_specific.h"
125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/gfx/geometry/size_base.h"
135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/gfx/gfx_export.h"
145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace gfx {
165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// A floating version of gfx::Size.
185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class GFX_EXPORT SizeF : public SizeBase<SizeF, float> {
195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) public:
205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  SizeF() : SizeBase<SizeF, float>(0, 0) {}
215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  SizeF(float width, float height) : SizeBase<SizeF, float>(width, height) {}
225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ~SizeF() {}
235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  void Scale(float scale) {
255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    Scale(scale, scale);
265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  void Scale(float x_scale, float y_scale) {
295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    SetSize(width() * x_scale, height() * y_scale);
305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  std::string ToString() const;
335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)};
345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)inline bool operator==(const SizeF& lhs, const SizeF& rhs) {
365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return lhs.width() == rhs.width() && lhs.height() == rhs.height();
375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)inline bool operator!=(const SizeF& lhs, const SizeF& rhs) {
405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return !(lhs == rhs);
415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)GFX_EXPORT SizeF ScaleSize(const SizeF& p, float x_scale, float y_scale);
445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)inline SizeF ScaleSize(const SizeF& p, float scale) {
465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return ScaleSize(p, scale, scale);
475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
491320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#if !defined(COMPILER_MSVC) && !defined(__native_client__)
505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)extern template class SizeBase<SizeF, float>;
515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#endif
525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
53116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch// This is declared here for use in gtest-based unit tests but is defined in
54116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch// the gfx_test_support target. Depend on that to use this in your unit test.
55116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch// This should not be used in production code - call ToString() instead.
56116680a4aac90f2aa7413d9095a592090648e557Ben Murdochvoid PrintTo(const SizeF& size, ::std::ostream* os);
57116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}  // namespace gfx
595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#endif  // UI_GFX_GEOMETRY_SIZE_F_H_
61