diff options
author | beng@google.com <beng@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-07-31 00:47:11 +0000 |
---|---|---|
committer | beng@google.com <beng@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-07-31 00:47:11 +0000 |
commit | f3181317c218aceb35bd3324d5c796901b7b657f (patch) | |
tree | 8485bc6bdad8c34b23abed5d84c2c7b56ec63063 /chrome | |
parent | b2a4b9f96997dc3b929b5b9930325a030a8294e3 (diff) | |
download | chromium_src-f3181317c218aceb35bd3324d5c796901b7b657f.zip chromium_src-f3181317c218aceb35bd3324d5c796901b7b657f.tar.gz chromium_src-f3181317c218aceb35bd3324d5c796901b7b657f.tar.bz2 |
forgot these files
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@154 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/views/client_view.cc | 394 | ||||
-rw-r--r-- | chrome/views/client_view.h | 130 | ||||
-rw-r--r-- | chrome/views/custom_frame_window.h | 9 | ||||
-rw-r--r-- | chrome/views/non_client_view.h | 2 |
4 files changed, 75 insertions, 460 deletions
diff --git a/chrome/views/client_view.cc b/chrome/views/client_view.cc index 7bc7638..89894e7 100644 --- a/chrome/views/client_view.cc +++ b/chrome/views/client_view.cc @@ -27,399 +27,49 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include <windows.h> -#include <uxtheme.h> -#include <vsstyle.h> - +#include "base/logging.h" #include "chrome/views/client_view.h" -#include "base/gfx/native_theme.h" -#include "chrome/browser/standard_layout.h" -#include "chrome/common/gfx/chrome_canvas.h" -#include "chrome/common/gfx/chrome_font.h" -#include "chrome/common/l10n_util.h" -#include "chrome/common/resource_bundle.h" -#include "chrome/common/win_util.h" -#include "chrome/views/window.h" -#include "generated_resources.h" - -namespace { - -// Updates any of the standard buttons according to the delegate. -void UpdateButtonHelper(ChromeViews::NativeButton* button_view, - ChromeViews::DialogDelegate* delegate, - ChromeViews::DialogDelegate::DialogButton button) { - std::wstring label = delegate->GetDialogButtonLabel(button); - if (!label.empty()) - button_view->SetLabel(label); - button_view->SetEnabled(delegate->IsDialogButtonEnabled(button)); - button_view->SetVisible(delegate->IsDialogButtonVisible(button)); -} - -} // namespace - namespace ChromeViews { -// static -ChromeFont ClientView::dialog_button_font_; -static const int kDialogMinButtonWidth = 75; -static const int kDialogButtonLabelSpacing = 16; -static const int kDialogButtonContentSpacing = 0; - -// The group used by the buttons. This name is chosen voluntarily big not to -// conflict with other groups that could be in the dialog content. -static const int kButtonGroup = 6666; - -namespace { - -// DialogButton ---------------------------------------------------------------- - -// DialogButtons is used for the ok/cancel buttons of the window. DialogButton -// forwrds AcceleratorPressed to the delegate. - -class DialogButton : public NativeButton { - public: - DialogButton(Window* owner, - DialogDelegate::DialogButton type, - const std::wstring& title, - bool is_default) - : NativeButton(title, is_default), owner_(owner), type_(type) { - } - - // Overriden to forward to the delegate. - virtual bool AcceleratorPressed(const Accelerator& accelerator) { - if (!owner_->window_delegate()->AsDialogDelegate()-> - AreAcceleratorsEnabled(type_)) { - return false; - } - return NativeButton::AcceleratorPressed(accelerator); - } - - private: - Window* owner_; - const DialogDelegate::DialogButton type_; - - DISALLOW_EVIL_CONSTRUCTORS(DialogButton); -}; - -} // namespace - -//////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// // ClientView, public: -ClientView::ClientView(Window* owner, View* contents_view) - : ok_button_(NULL), - cancel_button_(NULL), - extra_view_(NULL), - owner_(owner), - contents_view_(contents_view) { - DCHECK(owner_); - InitClass(); -} - -ClientView::~ClientView() { -} - -void ClientView::ShowDialogButtons() { - if (!owner_->window_delegate()) - return; - - DialogDelegate* dd = owner_->window_delegate()->AsDialogDelegate(); - if (!dd) - return; - - int buttons = dd->GetDialogButtons(); - - if (buttons & DialogDelegate::DIALOGBUTTON_OK && !ok_button_) { - std::wstring label = - dd->GetDialogButtonLabel(DialogDelegate::DIALOGBUTTON_OK); - if (label.empty()) - label = l10n_util::GetString(IDS_OK); - ok_button_ = new DialogButton( - owner_, DialogDelegate::DIALOGBUTTON_OK, - label, - (dd->GetDefaultDialogButton() & DialogDelegate::DIALOGBUTTON_OK) != 0); - ok_button_->SetListener(this); - ok_button_->SetGroup(kButtonGroup); - if (!cancel_button_) - ok_button_->AddAccelerator(Accelerator(VK_ESCAPE, false, false, false)); - AddChildView(ok_button_); - } - if (buttons & DialogDelegate::DIALOGBUTTON_CANCEL && !cancel_button_) { - std::wstring label = - dd->GetDialogButtonLabel(DialogDelegate::DIALOGBUTTON_CANCEL); - if (label.empty()) { - if (buttons & DialogDelegate::DIALOGBUTTON_OK) { - label = l10n_util::GetString(IDS_CANCEL); - } else { - label = l10n_util::GetString(IDS_CLOSE); - } - } - cancel_button_ = new DialogButton( - owner_, DialogDelegate::DIALOGBUTTON_CANCEL, - label, - (dd->GetDefaultDialogButton() & DialogDelegate::DIALOGBUTTON_CANCEL) - != 0); - cancel_button_->SetListener(this); - cancel_button_->SetGroup(kButtonGroup); - cancel_button_->AddAccelerator(Accelerator(VK_ESCAPE, false, false, false)); - AddChildView(cancel_button_); - } - - ChromeViews::View* extra_view = dd->GetExtraView(); - if (extra_view && !extra_view_) { - extra_view_ = extra_view; - extra_view_->SetGroup(kButtonGroup); - AddChildView(extra_view_); - } - if (!buttons) { - // Register the escape key as an accelerator which will close the window - // if there are no dialog buttons. - AddAccelerator(Accelerator(VK_ESCAPE, false, false, false)); - } -} -// Changing dialog labels will change button widths. -void ClientView::UpdateDialogButtons() { - if (!owner_->window_delegate()) - return; - - DialogDelegate* dd = owner_->window_delegate()->AsDialogDelegate(); - if (!dd) - return; - - int buttons = dd->GetDialogButtons(); - - if (buttons & DialogDelegate::DIALOGBUTTON_OK) - UpdateButtonHelper(ok_button_, dd, DialogDelegate::DIALOGBUTTON_OK); - - if (buttons & DialogDelegate::DIALOGBUTTON_CANCEL) - UpdateButtonHelper(cancel_button_, dd, DialogDelegate::DIALOGBUTTON_CANCEL); - - LayoutDialogButtons(); - SchedulePaint(); +ClientView::ClientView(Window* window, View* contents_view) + : window_(window), + contents_view_(contents_view) { + DCHECK(window && contents_view); } -bool ClientView::PointIsInSizeBox(const gfx::Point& point) { - CPoint temp = point.ToPOINT(); - View::ConvertPointFromViewContainer(this, &temp); - return size_box_bounds_.Contains(temp.x, temp.y); +int ClientView::NonClientHitTest(const gfx::Point& point) { + CRect bounds; + GetBounds(&bounds, APPLY_MIRRORING_TRANSFORMATION); + if (gfx::Rect(bounds).Contains(point.x(), point.y())) + return HTCLIENT; + return HTNOWHERE; } -//////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// // ClientView, View overrides: -static void FillViewWithSysColor(ChromeCanvas* canvas, View* view, - COLORREF color) { - SkColor sk_color = - SkColorSetRGB(GetRValue(color), GetGValue(color), GetBValue(color)); - canvas->FillRectInt(sk_color, 0, 0, view->GetWidth(), view->GetHeight()); -} - -void ClientView::Paint(ChromeCanvas* canvas) { - if (!owner_->window_delegate()) - return; - - if (owner_->window_delegate()->AsDialogDelegate()) { - FillViewWithSysColor(canvas, this, GetSysColor(COLOR_3DFACE)); - } else { - // TODO(beng): (Cleanup) this should be COLOR_WINDOW but until the App - // Install wizard is updated to use the DialogDelegate somehow, - // we'll just use this value here. - FillViewWithSysColor(canvas, this, GetSysColor(COLOR_3DFACE)); - } -} - -void ClientView::PaintChildren(ChromeCanvas* canvas) { - View::PaintChildren(canvas); - if (!owner_->IsMaximized() && !owner_->IsMinimized()) - PaintSizeBox(canvas); -} - -void ClientView::Layout() { - if (has_dialog_buttons()) - LayoutDialogButtons(); - LayoutContentsView(); -} - -void ClientView::ViewHierarchyChanged(bool is_add, View* parent, View* child) { - if (is_add && child == this) { - // Can only add and update the dialog buttons _after_ they are added to the - // view hierarchy since they are native controls and require the - // ViewContainer's HWND. - ShowDialogButtons(); - // Only add the contents_view_ once, and only when we ourselves are added - // to the view hierarchy, since some contents_view_s assume that when they - // are added to the hierarchy a HWND exists, when it may not, since we are - // not yet added... - if (contents_view_ && contents_view_->GetParent() != this) - AddChildView(contents_view_); - UpdateDialogButtons(); - Layout(); - } -} - -void ClientView::DidChangeBounds(const CRect& prev, const CRect& next) { - Layout(); -} - void ClientView::GetPreferredSize(CSize* out) { DCHECK(out); contents_view_->GetPreferredSize(out); - int button_height = 0; - if (has_dialog_buttons()) { - if (cancel_button_) - button_height = cancel_button_->GetHeight(); - else - button_height = ok_button_->GetHeight(); - // Account for padding above and below the button. - button_height += kDialogButtonContentSpacing + kButtonVEdgeMargin; - } - out->cy += button_height; -} - -bool ClientView::AcceleratorPressed(const Accelerator& accelerator) { - DCHECK(accelerator.GetKeyCode() == VK_ESCAPE); // We only expect Escape key. - owner_->Close(); - return true; -} - -//////////////////////////////////////////////////////////////////////////////// -// ClientView, NativeButton::Listener implementation: - -void ClientView::ButtonPressed(NativeButton* sender) { - if (sender == ok_button_) { - owner_->AcceptWindow(); - } else if (sender == cancel_button_) { - owner_->CancelWindow(); - } -} - -//////////////////////////////////////////////////////////////////////////////// -// ClientView, private: - -void ClientView::PaintSizeBox(ChromeCanvas* canvas) { - if (!owner_->window_delegate()) - return; - - if (owner_->window_delegate()->CanResize() || - owner_->window_delegate()->CanMaximize()) { - HDC dc = canvas->beginPlatformPaint(); - SIZE gripper_size = { 0, 0 }; - gfx::NativeTheme::instance()->GetThemePartSize( - gfx::NativeTheme::STATUS, dc, SP_GRIPPER, 1, NULL, TS_TRUE, - &gripper_size); - - // TODO(beng): (http://b/1085509) In "classic" rendering mode, there isn't - // a theme-supplied gripper. We should probably improvise - // something, which would also require changing |gripper_size| - // to have different default values, too... - CRect gripper_bounds; - GetLocalBounds(&gripper_bounds, false); - gripper_bounds.left = gripper_bounds.right - gripper_size.cx; - gripper_bounds.top = gripper_bounds.bottom - gripper_size.cy; - size_box_bounds_ = gripper_bounds; - gfx::NativeTheme::instance()->PaintStatusGripper( - dc, SP_PANE, 1, 0, gripper_bounds); - canvas->endPlatformPaint(); - } -} - -int ClientView::GetButtonWidth(DialogDelegate::DialogButton button) { - if (!owner_->window_delegate()) - return kDialogMinButtonWidth; - - DialogDelegate* dd = owner_->window_delegate()->AsDialogDelegate(); - DCHECK(dd); - - std::wstring button_label = dd->GetDialogButtonLabel(button); - int string_width = dialog_button_font_.GetStringWidth(button_label); - return std::max(string_width + kDialogButtonLabelSpacing, - kDialogMinButtonWidth); } -void ClientView::LayoutDialogButtons() { - CRect extra_bounds; - if (cancel_button_) { - CSize ps; - cancel_button_->GetPreferredSize(&ps); - CRect lb; - GetLocalBounds(&lb, false); - int button_width = GetButtonWidth(DialogDelegate::DIALOGBUTTON_CANCEL); - CRect bounds; - bounds.left = lb.right - button_width - kButtonHEdgeMargin; - bounds.top = lb.bottom - ps.cy - kButtonVEdgeMargin; - bounds.right = bounds.left + button_width; - bounds.bottom = bounds.top + ps.cy; - cancel_button_->SetBounds(bounds); - // The extra view bounds are dependent on this button. - extra_bounds.right = bounds.left; - extra_bounds.top = bounds.top; - } - if (ok_button_) { - CSize ps; - ok_button_->GetPreferredSize(&ps); - CRect lb; - GetLocalBounds(&lb, false); - int button_width = GetButtonWidth(DialogDelegate::DIALOGBUTTON_OK); - int ok_button_right = lb.right - kButtonHEdgeMargin; - if (cancel_button_) - ok_button_right = cancel_button_->GetX() - kRelatedButtonHSpacing; - CRect bounds; - bounds.left = ok_button_right - button_width; - bounds.top = lb.bottom - ps.cy - kButtonVEdgeMargin; - bounds.right = ok_button_right; - bounds.bottom = bounds.top + ps.cy; - ok_button_->SetBounds(bounds); - // The extra view bounds are dependent on this button. - extra_bounds.right = bounds.left; - extra_bounds.top = bounds.top; - } - if (extra_view_) { - CSize ps; - extra_view_->GetPreferredSize(&ps); - CRect lb; - GetLocalBounds(&lb, false); - extra_bounds.left = lb.left + kButtonHEdgeMargin; - extra_bounds.bottom = extra_bounds.top + ps.cy; - extra_view_->SetBounds(extra_bounds); +void ClientView::ViewHierarchyChanged(bool is_add, View* parent, View* child) { + if (is_add && child == this) { + DCHECK(GetViewContainer()); + AddChildView(contents_view_); } } -void ClientView::LayoutContentsView() { - // We acquire a |contents_view_| ptr when we are constructed, but this can be - // NULL (for testing purposes). Also, we explicitly don't immediately insert - // the contents_view_ into the hierarchy until we ourselves are inserted, - // because the contents_view_ may have initialization that relies on a HWND - // at the time it is inserted into _any_ hierarchy. So this check is to - // ensure the contents_view_ is in a valid state as a child of this window - // before trying to lay it out to our size. - if (contents_view_ && contents_view_->GetParent() == this) { - int button_height = 0; - if (has_dialog_buttons()) { - if (cancel_button_) - button_height = cancel_button_->GetHeight(); - else - button_height = ok_button_->GetHeight(); - // Account for padding above and below the button. - button_height += kDialogButtonContentSpacing + kButtonVEdgeMargin; - } - - CRect lb; - GetLocalBounds(&lb, false); - lb.bottom = std::max(0, static_cast<int>(lb.bottom - button_height)); - contents_view_->SetBounds(lb); - contents_view_->Layout(); - } +void ClientView::DidChangeBounds(const CRect& previous, const CRect& current) { + Layout(); } -// static -void ClientView::InitClass() { - static bool initialized = false; - if (!initialized) { - ResourceBundle& rb = ResourceBundle::GetSharedInstance(); - dialog_button_font_ = rb.GetFont(ResourceBundle::BaseFont); - initialized = true; - } +void ClientView::Layout() { + contents_view_->SetBounds(0, 0, GetWidth(), GetHeight()); } -} +}; // namespace ChromeViews
\ No newline at end of file diff --git a/chrome/views/client_view.h b/chrome/views/client_view.h index 8631c44..f83887b 100644 --- a/chrome/views/client_view.h +++ b/chrome/views/client_view.h @@ -27,103 +27,75 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#ifndef CHROME_VIEWS_CLIENT_VIEW_H__ -#define CHROME_VIEWS_CLIENT_VIEW_H__ +#ifndef CHROME_VIEWS_CLIENT_VIEW_H_ +#define CHROME_VIEWS_CLIENT_VIEW_H_ -#include "chrome/common/gfx/chrome_font.h" -#include "chrome/views/dialog_delegate.h" -#include "chrome/views/native_button.h" +#include "chrome/views/view.h" namespace ChromeViews { +class DialogClientView; class Window; /////////////////////////////////////////////////////////////////////////////// // ClientView // -// A ClientView is a view representing the "Client" area of a Window. This is -// defined on Windows as being the portion of the window excluding the frame, -// title bar and window controls. -// -// This abstraction is used to provide both the native frame window class -// (ChromeViews::Window) and custom frame window class -// (ChromeViews::ChromeWindow) with a client view container and dialog button -// helper. ChromeWindow is used for all dialogs and windows on Windows XP and -// Windows Vista without Aero, and Window is used on Windows Vista with Aero, -// and so this class allows both Window types to share the same dialog button -// behavior. -// -/////////////////////////////////////////////////////////////////////////////// -class ClientView : public View, - public NativeButton::Listener { +// A ClientView is a View subclass that is used to occupy the "client area" +// of a window. It provides basic information to the window that contains it +// such as non-client hit testing information, sizing etc. Sub-classes of +// ClientView are used to create more elaborate contents, e.g. +// "DialogClientView". +class ClientView : public View { public: + // Constructs a ClientView object for the specified window with the specified + // contents. Since this object is created during the process of creating + // |window|, |contents_view| must be valid so we can determine the initial + // size of |window|. We call GetPreferredSize on |contents_view|, + // which should return something non-zero. ClientView(Window* window, View* contents_view); - virtual ~ClientView(); - - // Adds the dialog buttons required by the supplied WindowDelegate to the - // view. - void ShowDialogButtons(); - - // Updates the enabled state and label of the buttons required by the - // supplied WindowDelegate - void UpdateDialogButtons(); - - // Returns true if the specified point (in screen coordinates) is within the - // resize box area of the window. - bool PointIsInSizeBox(const gfx::Point& point); - - // Accessors in case the user wishes to adjust these buttons. - NativeButton* ok_button() const { return ok_button_; } - NativeButton* cancel_button() const { return cancel_button_; } + virtual ~ClientView() {} + + // Manual RTTI ftw. + virtual DialogClientView* AsDialogClientView() { return NULL; } + + // Returns true to signal that the Window can be closed. Specialized + // ClientView subclasses can override this default behavior to allow the + // close to be blocked until the user corrects mistakes, accepts a warning + // dialog, etc. + virtual bool CanClose() const { return true; } + + // Tests to see if the specified point (in view coordinates) is within the + // bounds of this view. If so, it returns HTCLIENT in this default + // implementation. If it is outside the bounds of this view, this must return + // HTNOWHERE to tell the caller to do further processing to determine where + // in the non-client area it is (if it is). + // Subclasses of ClientView can extend this logic by overriding this method + // to detect if regions within the client area count as parts of the "non- + // client" area. A good example of this is the size box at the bottom right + // corner of resizable dialog boxes. + virtual int NonClientHitTest(const gfx::Point& point); + + // Overridden from View: + virtual void GetPreferredSize(CSize* out); - // View overrides: - virtual void Paint(ChromeCanvas* canvas); - virtual void PaintChildren(ChromeCanvas* canvas); - virtual void Layout(); + protected: + // Overridden from View: virtual void ViewHierarchyChanged(bool is_add, View* parent, View* child); - virtual void DidChangeBounds(const CRect& prev, const CRect& next); - virtual void GetPreferredSize(CSize* out); - virtual bool AcceleratorPressed(const Accelerator& accelerator); + virtual void DidChangeBounds(const CRect& previous, const CRect& current); + virtual void Layout(); - // NativeButton::Listener implementation: - virtual void ButtonPressed(NativeButton* sender); + // Accessors for private data members. + Window* window() const { return window_; } + View* contents_view() const { return contents_view_; } private: - // Paint the size box in the bottom right corner of the window if it is - // resizable. - void PaintSizeBox(ChromeCanvas* canvas); - - // Returns the width of the specified dialog button using the correct font. - int GetButtonWidth(DialogDelegate::DialogButton button); - - // Position and size various sub-views. - void LayoutDialogButtons(); - void LayoutContentsView(); - - bool has_dialog_buttons() const { return ok_button_ || cancel_button_; } - - // The dialog buttons. - NativeButton* ok_button_; - NativeButton* cancel_button_; - // The button-level extra view, NULL unless the dialog delegate supplies one. - View* extra_view_; + // The Window that hosts this ClientView. + Window* window_; - // The layout rect of the size box, when visible. - gfx::Rect size_box_bounds_; - - // The Window that owns us. - Window* owner_; - - // The contents of the client area, supplied by the caller. + // The View that this ClientView contains. View* contents_view_; - - // Static resource initialization - static void InitClass(); - static ChromeFont dialog_button_font_; - - DISALLOW_EVIL_CONSTRUCTORS(ClientView); }; -} +} // namespace ChromeViews -#endif // #ifndef CHROME_VIEWS_CLIENT_VIEW_H__ +#endif // #ifndef CHROME_VIEWS_CLIENT_VIEW_H_
\ No newline at end of file diff --git a/chrome/views/custom_frame_window.h b/chrome/views/custom_frame_window.h index 72c7c1c..d61b6b8 100644 --- a/chrome/views/custom_frame_window.h +++ b/chrome/views/custom_frame_window.h @@ -55,13 +55,6 @@ class CustomFrameWindow : public Window { NonClientView* non_client_view); virtual ~CustomFrameWindow(); - // Create the CustomFrameWindow. - // The parent of this window is always the desktop, however the owner is a - // window that this window is dependent on, if this window is opened as a - // modal dialog or dependent window. This is NULL if the window is not - // dependent on any other window. - virtual void Init(HWND owner, const gfx::Rect& bounds); - // Executes the specified SC_command. void ExecuteSystemMenuCommand(int command); @@ -69,6 +62,8 @@ class CustomFrameWindow : public Window { bool is_active() const { return is_active_; } // Overridden from Window: + virtual void Init(HWND parent, const gfx::Rect& bounds); + virtual void SetClientView(ClientView* client_view); virtual gfx::Size CalculateWindowSizeForClientSize( const gfx::Size& client_size) const; virtual void UpdateWindowTitle(); diff --git a/chrome/views/non_client_view.h b/chrome/views/non_client_view.h index f30e956..9c83a67 100644 --- a/chrome/views/non_client_view.h +++ b/chrome/views/non_client_view.h @@ -52,8 +52,6 @@ class ClientView; // class NonClientView : public View { public: - virtual void Init(ClientView* client_view) = 0; - // Calculates the bounds of the client area of the window assuming the // window is sized to |width| and |height|. virtual gfx::Rect CalculateClientAreaBounds(int width, |