summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/frame
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/chromeos/frame')
-rw-r--r--chrome/browser/chromeos/frame/bubble_frame_view.cc124
-rw-r--r--chrome/browser/chromeos/frame/bubble_frame_view.h63
-rw-r--r--chrome/browser/chromeos/frame/bubble_window.cc38
-rw-r--r--chrome/browser/chromeos/frame/bubble_window.h37
4 files changed, 262 insertions, 0 deletions
diff --git a/chrome/browser/chromeos/frame/bubble_frame_view.cc b/chrome/browser/chromeos/frame/bubble_frame_view.cc
new file mode 100644
index 0000000..38b2be6
--- /dev/null
+++ b/chrome/browser/chromeos/frame/bubble_frame_view.cc
@@ -0,0 +1,124 @@
+// 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.
+
+#include "chrome/browser/chromeos/frame/bubble_frame_view.h"
+
+#include "gfx/canvas_skia.h"
+#include "gfx/font.h"
+#include "gfx/insets.h"
+#include "gfx/path.h"
+#include "gfx/rect.h"
+#include "chrome/browser/chromeos/frame/bubble_window.h"
+#include "chrome/browser/views/bubble_border.h"
+#include "views/controls/label.h"
+#include "views/window/hit_test.h"
+#include "views/window/window.h"
+#include "views/window/window_delegate.h"
+#include "third_party/skia/include/core/SkPaint.h"
+
+namespace {
+
+static const int kTitleTopPadding = 10;
+static const int kTitleContentPadding = 10;
+static const int kHorizontalPadding = 10;
+
+} // namespace
+
+namespace chromeos {
+
+BubbleFrameView::BubbleFrameView(views::Window* frame)
+ : frame_(frame),
+ title_(NULL) {
+ set_border(new BubbleBorder(BubbleBorder::NONE));
+
+ title_ = new views::Label(frame_->GetDelegate()->GetWindowTitle());
+ title_->SetFont(title_->font().DeriveFont(1, gfx::Font::BOLD));
+ AddChildView(title_);
+}
+
+BubbleFrameView::~BubbleFrameView() {
+}
+
+gfx::Rect BubbleFrameView::GetBoundsForClientView() const {
+ return client_view_bounds_;
+}
+
+gfx::Rect BubbleFrameView::GetWindowBoundsForClientBounds(
+ const gfx::Rect& client_bounds) const {
+ gfx::Insets insets = GetInsets();
+ gfx::Size title_size = title_->GetPreferredSize();
+ int top_height = insets.top() + title_size.height() + kTitleContentPadding;
+ return gfx::Rect(std::max(0, client_bounds.x() - insets.left()),
+ std::max(0, client_bounds.y() - top_height),
+ client_bounds.width() + insets.width(),
+ client_bounds.height() + top_height + insets.bottom());
+}
+
+int BubbleFrameView::NonClientHitTest(const gfx::Point& point) {
+ return HTNOWHERE;
+}
+
+void BubbleFrameView::GetWindowMask(const gfx::Size& size,
+ gfx::Path* window_mask) {
+}
+
+void BubbleFrameView::EnableClose(bool enable) {
+}
+
+void BubbleFrameView::ResetWindowControls() {
+}
+
+gfx::Insets BubbleFrameView::GetInsets() const {
+ gfx::Insets border_insets;
+ border()->GetInsets(&border_insets);
+
+ gfx::Insets insets(kTitleTopPadding,
+ kHorizontalPadding,
+ 0,
+ kHorizontalPadding);
+ insets += border_insets;
+ return insets;
+}
+
+gfx::Size BubbleFrameView::GetPreferredSize() {
+ gfx::Size pref = frame_->GetClientView()->GetPreferredSize();
+ gfx::Rect bounds(0, 0, pref.width(), pref.height());
+ return frame_->GetNonClientView()->GetWindowBoundsForClientBounds(
+ bounds).size();
+}
+
+void BubbleFrameView::Layout() {
+ gfx::Insets insets = GetInsets();
+
+ gfx::Size title_size = title_->GetPreferredSize();
+ title_->SetBounds(insets.left(), insets.top(),
+ std::max(0, width() - insets.width()),
+ title_size.height());
+
+ int top_height = insets.top() + title_size.height() + kTitleContentPadding;
+ client_view_bounds_.SetRect(insets.left(), top_height,
+ std::max(0, width() - insets.width()),
+ std::max(0, height() - top_height - insets.bottom()));
+}
+
+void BubbleFrameView::Paint(gfx::Canvas* canvas) {
+ // The border of this view creates an anti-aliased round-rect region for the
+ // contents, which we need to fill with the background color.
+ SkPaint paint;
+ paint.setAntiAlias(true);
+ paint.setStyle(SkPaint::kFill_Style);
+ paint.setColor(BubbleWindow::kBackgroundColor);
+ gfx::Path path;
+ gfx::Rect bounds(GetLocalBounds(false));
+ SkRect rect;
+ rect.set(SkIntToScalar(bounds.x()), SkIntToScalar(bounds.y()),
+ SkIntToScalar(bounds.right()), SkIntToScalar(bounds.bottom()));
+ SkScalar radius = SkIntToScalar(BubbleBorder::GetCornerRadius());
+ path.addRoundRect(rect, radius, radius);
+ canvas->AsCanvasSkia()->drawPath(path, paint);
+
+ PaintBorder(canvas);
+}
+
+} // namespace chromeos
diff --git a/chrome/browser/chromeos/frame/bubble_frame_view.h b/chrome/browser/chromeos/frame/bubble_frame_view.h
new file mode 100644
index 0000000..18505f7
--- /dev/null
+++ b/chrome/browser/chromeos/frame/bubble_frame_view.h
@@ -0,0 +1,63 @@
+// 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_BROWSER_CHROMEOS_FRAME_BUBBLE_FRAME_VIEW_H_
+#define CHROME_BROWSER_CHROMEOS_FRAME_BUBBLE_FRAME_VIEW_H_
+#pragma once
+
+#include "views/window/non_client_view.h"
+
+namespace gfx {
+class Insets;
+class Path;
+class Point;
+class Rect;
+class Size;
+}
+
+namespace views {
+class Label;
+class Window;
+}
+
+namespace chromeos {
+
+// BubbleFrameView implements a BubbleBorder based window frame.
+class BubbleFrameView : public views::NonClientFrameView {
+ public:
+ explicit BubbleFrameView(views::Window* frame);
+ virtual ~BubbleFrameView();
+
+ // Overridden from views::NonClientFrameView:
+ virtual gfx::Rect GetBoundsForClientView() const;
+ virtual gfx::Rect GetWindowBoundsForClientBounds(
+ const gfx::Rect& client_bounds) const;
+ virtual int NonClientHitTest(const gfx::Point& point);
+ virtual void GetWindowMask(const gfx::Size& size, gfx::Path* window_mask);
+ virtual void EnableClose(bool enable);
+ virtual void ResetWindowControls();
+
+ // View overrides:
+ virtual gfx::Insets GetInsets() const;
+ virtual gfx::Size GetPreferredSize();
+ virtual void Layout();
+ virtual void Paint(gfx::Canvas* canvas);
+
+ private:
+ // The window that owns this view.
+ views::Window* frame_;
+
+ // Title label
+ views::Label* title_;
+
+ // The bounds of the client view, in this view's coordinates.
+ gfx::Rect client_view_bounds_;
+
+ DISALLOW_COPY_AND_ASSIGN(BubbleFrameView);
+};
+
+} // namespace chromeos
+
+#endif // CHROME_BROWSER_CHROMEOS_FRAME_BUBBLE_FRAME_VIEW_H_
+
diff --git a/chrome/browser/chromeos/frame/bubble_window.cc b/chrome/browser/chromeos/frame/bubble_window.cc
new file mode 100644
index 0000000..ff667e8
--- /dev/null
+++ b/chrome/browser/chromeos/frame/bubble_window.cc
@@ -0,0 +1,38 @@
+// 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.
+
+#include "chrome/browser/chromeos/frame/bubble_window.h"
+
+#include "chrome/browser/chromeos/frame/bubble_frame_view.h"
+#include "chrome/browser/chromeos/wm_ipc.h"
+#include "cros/chromeos_wm_ipc_enums.h"
+#include "views/window/non_client_view.h"
+
+namespace chromeos {
+
+// static
+const SkColor BubbleWindow::kBackgroundColor = SK_ColorWHITE;
+
+BubbleWindow::BubbleWindow(views::WindowDelegate* window_delegate)
+ : views::WindowGtk(window_delegate) {
+ MakeTransparent();
+}
+
+views::Window* BubbleWindow::Create(
+ gfx::NativeWindow parent,
+ const gfx::Rect& bounds,
+ views::WindowDelegate* window_delegate) {
+ BubbleWindow* window = new BubbleWindow(window_delegate);
+ window->GetNonClientView()->SetFrameView(new BubbleFrameView(window));
+ window->Init(parent, bounds);
+
+ chromeos::WmIpc::instance()->SetWindowType(
+ window->GetNativeView(),
+ chromeos::WM_IPC_WINDOW_CHROME_INFO_BUBBLE,
+ NULL);
+
+ return window;
+}
+
+} // namespace chromeos
diff --git a/chrome/browser/chromeos/frame/bubble_window.h b/chrome/browser/chromeos/frame/bubble_window.h
new file mode 100644
index 0000000..f9ea7a7
--- /dev/null
+++ b/chrome/browser/chromeos/frame/bubble_window.h
@@ -0,0 +1,37 @@
+// 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_BROWSER_CHROMEOS_FRAME_BUBBLE_WINDOW_H_
+#define CHROME_BROWSER_CHROMEOS_FRAME_BUBBLE_WINDOW_H_
+#pragma once
+
+#include "third_party/skia/include/core/SkColor.h"
+#include "views/window/window_gtk.h"
+
+namespace gfx {
+class Rect;
+}
+
+namespace views {
+class WindowDelegate;
+}
+
+namespace chromeos {
+
+// A window that uses BubbleFrameView as its frame.
+class BubbleWindow : public views::WindowGtk {
+ public:
+ static views::Window* Create(gfx::NativeWindow parent,
+ const gfx::Rect& bounds,
+ views::WindowDelegate* window_delegate);
+
+ static const SkColor kBackgroundColor;
+
+ protected:
+ explicit BubbleWindow(views::WindowDelegate* window_delegate);
+};
+
+} // namespace chromeos
+
+#endif // CHROME_BROWSER_CHROMEOS_FRAME_BUBBLE_WINDOW_H_