| Index: ui/views_core/bridged_view_mac.h
|
| diff --git a/ui/views_core/bridged_view_mac.h b/ui/views_core/bridged_view_mac.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..7a7985f7fe30c2aab71da1a3cc12446221375121
|
| --- /dev/null
|
| +++ b/ui/views_core/bridged_view_mac.h
|
| @@ -0,0 +1,75 @@
|
| +// 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.
|
| +
|
| +#ifndef UI_VIEWS_CORE_BRIDGED_VIEW_MAC_H_
|
| +#define UI_VIEWS_CORE_BRIDGED_VIEW_MAC_H_
|
| +
|
| +#include <stddef.h>
|
| +
|
| +#include "base/mac/scoped_nsobject.h"
|
| +#include "ui/views/views_export.h"
|
| +
|
| +@class BridgedViewImpl;
|
| +@class NSView;
|
| +
|
| +namespace views {
|
| +
|
| +class View;
|
| +
|
| +// Represents a toolkit-view that has been bridged so that it can be painted
|
| +// using an NSView. This is the non-templatized base.
|
| +class VIEWS_EXPORT BridgedViewBase {
|
| + typedef base::scoped_nsobject<BridgedViewImpl> BridgedViewBase::*Testable;
|
| +
|
| + public:
|
| + // Allow bool-conversion, returning the private pointer-to-member trick to
|
| + // avoid returning something that easily converts to int.
|
| + operator Testable() const {
|
| + return bridged_view_.get() ? &BridgedViewBase::bridged_view_ : NULL;
|
| + }
|
| +
|
| + // Returns the NSView side of the bridge, or nil.
|
| + NSView* GetNSView();
|
| +
|
| + // Returns the views::View side of the bridge, or NULL.
|
| + View* GetView();
|
| +
|
| + protected:
|
| + BridgedViewBase();
|
| + explicit BridgedViewBase(View* view);
|
| + ~BridgedViewBase();
|
| +
|
| + void ResetView(View* view);
|
| +
|
| + private:
|
| + base::scoped_nsobject<BridgedViewImpl> bridged_view_;
|
| +};
|
| +
|
| +// Templatized scoped_ptr-style class for representing a bridged views::View.
|
| +// Members of the views::View subtype are accessed via the strongly typed
|
| +// operator->(). When a BridgedView goes out of scope, the owned |view| is
|
| +// removed from the hosting NSView superview and immediately destroyed. The
|
| +// NSView is released, but it is reference counted so could still hang around
|
| +// for a while.
|
| +template <class T>
|
| +class BridgedView : public BridgedViewBase {
|
| + public:
|
| + // Construct with an initially NULL bridge.
|
| + BridgedView() : BridgedViewBase() {}
|
| +
|
| + // Takes ownership of |view|.
|
| + explicit BridgedView(T* view) : BridgedViewBase(view) {}
|
| +
|
| + // Takes ownership of |view|.
|
| + void reset(T* view = NULL) { ResetView(view); }
|
| +
|
| + T* get() { return static_cast<T*>(GetView()); }
|
| + const T* get() const { return static_cast<const T*>(GetView()); }
|
| + T* operator->() { return get(); }
|
| + const T* operator->() const { return get(); }
|
| +};
|
| +
|
| +} // namespace views
|
| +
|
| +#endif // UI_VIEWS_CORE_BRIDGED_VIEW_MAC_H_
|
|
|