view_prop.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright (c) 2011 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. #ifndef UI_BASE_VIEW_PROP_H_
  5. #define UI_BASE_VIEW_PROP_H_
  6. #include "base/component_export.h"
  7. #include "base/memory/ref_counted.h"
  8. #include "build/build_config.h"
  9. #include "ui/gfx/native_widget_types.h"
  10. #if !BUILDFLAG(IS_WIN) && !defined(USE_AURA)
  11. #error view_prop.h is only for windows and aura builds.
  12. #endif
  13. namespace ui {
  14. // ViewProp maintains a key/value pair for a particular view. ViewProp is
  15. // designed as a replacement for the Win32's SetProp, but does not make use of
  16. // window manager memory. ViewProp shares similar semantics as SetProp, the
  17. // value for a particular view/key pair comes from the last ViewProp created.
  18. class COMPONENT_EXPORT(UI_BASE) ViewProp {
  19. public:
  20. // Associates data with a view/key pair. If a ViewProp has already been
  21. // created for the specified pair |data| replaces the current value.
  22. //
  23. // ViewProp does *not* make a copy of the char*, the pointer is used for
  24. // sorting.
  25. ViewProp(gfx::AcceleratedWidget view, const char* key, void* data);
  26. ViewProp(const ViewProp&) = delete;
  27. ViewProp& operator=(const ViewProp&) = delete;
  28. ~ViewProp();
  29. // Returns the value associated with the view/key pair, or NULL if there is
  30. // none.
  31. static void* GetValue(gfx::AcceleratedWidget view, const char* key);
  32. // Returns the key.
  33. const char* Key() const;
  34. private:
  35. class Data;
  36. // Stores the actual data.
  37. scoped_refptr<Data> data_;
  38. };
  39. } // namespace ui
  40. #endif // UI_BASE_VIEW_PROP_H_