Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7565)

Unified Diff: chrome_frame/infobars/internal/subclassing_window.h

Issue 4766003: Preview CL for adding an Infobar facility to Google Chrome Frame.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome_frame/infobars/internal/infobar_window.cc ('k') | chrome_frame/infobars/manager.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome_frame/infobars/internal/subclassing_window.h
===================================================================
--- chrome_frame/infobars/internal/subclassing_window.h (revision 0)
+++ chrome_frame/infobars/internal/subclassing_window.h (revision 0)
@@ -0,0 +1,107 @@
+// Copyright (c) 2010 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 CHROME_FRAME_INFOBARS_INTERNAL_SUBCLASSING_WINDOW_H_
+#define CHROME_FRAME_INFOBARS_INTERNAL_SUBCLASSING_WINDOW_H_
+
+#include <atlbase.h>
+#include <atlcrack.h>
+#include <atlwin.h>
+
+#include "base/basictypes.h"
+#include "base/logging.h"
+#include "base/scoped_ptr.h"
+#include "chrome_frame/utils.h"
+
+// Implements behavior common to HostWindowManager and DisplacedWindowManager.
+template<typename T> class SubclassingWindowWithDelegate
+ : public CWindowImpl<T> {
+ public:
+ // Allows clients to modify the dimensions of the displaced window.
+ // Through its destructor, allows clients to know when the subclassed window
+ // is destroyed.
+ class Delegate {
+ public:
+ // The delegate will be deleted when the subclassed window is destroyed.
+ virtual ~Delegate() {}
+
+ // Receives the natural dimensions of the displaced window. Upon return,
+ // rect should contain the adjusted dimensions (i.e., possibly reduced to
+ // accomodate an infobar).
+ virtual void AdjustDisplacedWindowDimensions(RECT* rect) = 0;
+ }; // class Delegate
+
+ SubclassingWindowWithDelegate() {}
+
+ // Returns true if the window is successfully subclassed, in which case this
+ // instance will take responsibility for its own destruction when the window
+ // is destroyed. If this method returns false, the caller should delete the
+ // instance immediately.
+ //
+ // Takes ownership of delegate in either case, deleting it when the window
+ // is destroyed (or immediately, in case of failure).
+ bool Initialize(HWND hwnd, Delegate* delegate) {
+ DCHECK(delegate != NULL);
+ DCHECK(delegate_ == NULL);
+ scoped_ptr<Delegate> new_delegate(delegate);
+
+ if (!::IsWindow(hwnd) || !SubclassWindow(hwnd)) {
+ PLOG(ERROR) << "Failed to subclass an HWND";
+ return false;
+ }
+
+ // Ensure we won't be unloaded while our window proc is attached to the tab
+ // window.
+ PinModule();
+
+ delegate_.swap(new_delegate);
+
+ return true;
+ }
+
+ // Returns the delegate associated with the specified window, if any.
+ static Delegate* GetDelegateForHwnd(HWND hwnd) {
+ return reinterpret_cast<Delegate*>(
+ ::SendMessage(hwnd, RegisterGetDelegateMessage(), NULL, NULL));
+ }
+
+ BEGIN_MSG_MAP_EX(SubclassingWindowWithDelegate)
+ MESSAGE_HANDLER(RegisterGetDelegateMessage(), OnGetDelegate)
+ MSG_WM_DESTROY(OnDestroy)
+ END_MSG_MAP()
+
+ // This instance is now free to be deleted.
+ virtual void OnFinalMessage(HWND hwnd) {
+ delete this;
+ }
+
+ protected:
+ scoped_ptr<Delegate>& delegate() { return delegate_; }
+
+ private:
+ // Registers a unique ID for our custom event.
+ static UINT RegisterGetDelegateMessage() {
+ static UINT message_id(
+ RegisterWindowMessage(L"SubclassingWindowWithDelegate::OnGetDelegate"));
+ return message_id;
+ }
+
+ // The subclassed window has been destroyed. Delete the delegate. We will
+ // delete ourselves in OnFinalMessage.
+ void OnDestroy() {
+ delegate_.reset();
+ }
+
+ LRESULT OnGetDelegate(UINT message,
+ WPARAM wparam,
+ LPARAM lparam,
+ BOOL& handled) {
+ return reinterpret_cast<LRESULT>(delegate_.get());
+ }
+
+ scoped_ptr<Delegate> delegate_;
+ DISALLOW_COPY_AND_ASSIGN(SubclassingWindowWithDelegate);
+}; // class SubclassingWindowWithDelegate
+
+#endif // CHROME_FRAME_INFOBARS_INTERNAL_SUBCLASSING_WINDOW_H_
Property changes on: chrome_frame\infobars\internal\subclassing_window.h
___________________________________________________________________
Added: svn:eol-style
+ LF
« no previous file with comments | « chrome_frame/infobars/internal/infobar_window.cc ('k') | chrome_frame/infobars/manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698