summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorerg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-19 23:54:35 +0000
committererg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-19 23:54:35 +0000
commit30bcc77df38a8775b28f6628a6f4270658b171e5 (patch)
tree225e1be3cb6a59fbd280db511941d13ec76c989e /chrome
parentfffc27d58ee6b52ea104b3d29a8a0ab7904410f4 (diff)
downloadchromium_src-30bcc77df38a8775b28f6628a6f4270658b171e5.zip
chromium_src-30bcc77df38a8775b28f6628a6f4270658b171e5.tar.gz
chromium_src-30bcc77df38a8775b28f6628a6f4270658b171e5.tar.bz2
Now have a TextButton rendering (sort of; doesn't respond to mouse events so
I don't know if it'll draw the border correctly). Now with fixes to compile under Windows. Review URL: http://codereview.chromium.org/42427 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@12172 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/gtk/browser_window_gtk.cc4
-rw-r--r--chrome/chrome.gyp3
-rw-r--r--chrome/views/SConscript4
-rw-r--r--chrome/views/controls/button/custom_button.cc17
-rw-r--r--chrome/views/controls/button/text_button.cc13
-rw-r--r--chrome/views/widget/root_view.cc13
-rw-r--r--chrome/views/widget/root_view.h4
-rw-r--r--chrome/views/widget/root_view_gtk.cc16
-rw-r--r--chrome/views/widget/root_view_win.cc14
-rw-r--r--chrome/views/widget/widget_gtk.cc8
-rw-r--r--chrome/views/window/window_win.cc8
11 files changed, 57 insertions, 47 deletions
diff --git a/chrome/browser/gtk/browser_window_gtk.cc b/chrome/browser/gtk/browser_window_gtk.cc
index f938005..43b620e 100644
--- a/chrome/browser/gtk/browser_window_gtk.cc
+++ b/chrome/browser/gtk/browser_window_gtk.cc
@@ -24,6 +24,7 @@
#include "chrome/browser/tab_contents/web_contents.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/resource_bundle.h"
+#include "chrome/views/controls/button/text_button.h"
#include "grit/theme_resources.h"
namespace {
@@ -155,6 +156,9 @@ BrowserWindowGtk::BrowserWindowGtk(Browser* browser)
if (parsed_command_line.HasSwitch(switches::kViewsGtk)) {
experimental_widget_.reset(new views::WidgetGtk());
experimental_widget_->Init(gfx::Rect(), false);
+ experimental_widget_->SetContentsView(
+ new views::TextButton(NULL, L"Button"));
+
gtk_box_pack_start(GTK_BOX(vbox_),
experimental_widget_->GetNativeView(),
false, false, 2);
diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp
index a0e7fe8..7f05e37 100644
--- a/chrome/chrome.gyp
+++ b/chrome/chrome.gyp
@@ -2457,8 +2457,6 @@
'views/accessibility/accessible_wrapper.cc',
'views/accessibility/view_accessibility.cc',
'views/accessibility/view_accessibility_wrapper.cc',
- 'views/controls/button/button.cc',
- 'views/controls/button/custom_button.cc',
'views/controls/scrollbar/bitmap_scroll_bar.cc',
'views/controls/button/image_button.cc',
'views/controls/button/button_dropdown.cc',
@@ -2481,7 +2479,6 @@
'views/controls/single_split_view.cc',
'views/controls/tabbed_pane.cc',
'views/controls/table/table_view.cc',
- 'views/controls/button/text_button.cc',
'views/controls/text_field.cc',
'views/controls/tree/tree_view.cc',
'views/widget/accelerator_handler.cc',
diff --git a/chrome/views/SConscript b/chrome/views/SConscript
index 81325aa..626a420 100644
--- a/chrome/views/SConscript
+++ b/chrome/views/SConscript
@@ -50,6 +50,8 @@ input_files = ChromeFileList([
'controls/scrollbar/bitmap_scroll_bar.h',
'border.cc',
'border.h',
+ 'controls/button/custom_button.cc',
+ 'controls/button/custom_button.h',
'controls/button/image_button.cc',
'controls/button/image_button.h',
'controls/button/button_dropdown.cc',
@@ -216,7 +218,6 @@ if env.Bit('linux'):
'accelerator.cc',
'accessibility/accessible_wrapper.cc',
'accessibility/view_accessibility.cc',
- 'controls/button/button.cc',
'controls/scrollbar/bitmap_scroll_bar.cc',
'controls/button/image_button.cc',
'controls/button/button_dropdown.cc',
@@ -239,7 +240,6 @@ if env.Bit('linux'):
'controls/single_split_view.cc',
'controls/tabbed_pane.cc',
'controls/table/table_view.cc',
- 'controls/button/text_button.cc',
'controls/text_field.cc',
'controls/tree/tree_view.cc',
'widget/accelerator_handler.cc',
diff --git a/chrome/views/controls/button/custom_button.cc b/chrome/views/controls/button/custom_button.cc
index 04e0a50..a01c0ab 100644
--- a/chrome/views/controls/button/custom_button.cc
+++ b/chrome/views/controls/button/custom_button.cc
@@ -4,13 +4,18 @@
#include "chrome/views/controls/button/custom_button.h"
-#include "base/base_drag_source.h"
-#include "chrome/browser/drag_utils.h"
+#include "base/keyboard_codes.h"
#include "chrome/common/drag_drop_types.h"
#include "chrome/common/gfx/chrome_canvas.h"
-#include "chrome/common/os_exchange_data.h"
#include "chrome/common/throb_animation.h"
+// TODO(erg): Write drag'n'drop for Linux.
+#if defined(OS_WIN)
+#include "base/base_drag_source.h"
+#include "chrome/browser/drag_utils.h"
+#include "chrome/common/os_exchange_data.h"
+#endif
+
namespace views {
// How long the hover animation takes if uninterrupted.
@@ -166,10 +171,10 @@ bool CustomButton::OnKeyPressed(const KeyEvent& e) {
// Space sets button state to pushed. Enter clicks the button. This matches
// the Windows native behavior of buttons, where Space clicks the button
// on KeyRelease and Enter clicks the button on KeyPressed.
- if (e.GetCharacter() == VK_SPACE) {
+ if (e.GetCharacter() == base::VKEY_SPACE) {
SetState(BS_PUSHED);
return true;
- } else if (e.GetCharacter() == VK_RETURN) {
+ } else if (e.GetCharacter() == base::VKEY_RETURN) {
SetState(BS_NORMAL);
NotifyClick(0);
return true;
@@ -180,7 +185,7 @@ bool CustomButton::OnKeyPressed(const KeyEvent& e) {
bool CustomButton::OnKeyReleased(const KeyEvent& e) {
if (state_ != BS_DISABLED) {
- if (e.GetCharacter() == VK_SPACE) {
+ if (e.GetCharacter() == base::VKEY_SPACE) {
SetState(BS_NORMAL);
NotifyClick(0);
return true;
diff --git a/chrome/views/controls/button/text_button.cc b/chrome/views/controls/button/text_button.cc
index c5f1ae6..a273d20 100644
--- a/chrome/views/controls/button/text_button.cc
+++ b/chrome/views/controls/button/text_button.cc
@@ -8,12 +8,15 @@
#include "chrome/common/l10n_util.h"
#include "chrome/common/resource_bundle.h"
#include "chrome/common/throb_animation.h"
-#include "chrome/common/win_util.h"
#include "chrome/views/controls/button/button.h"
#include "chrome/views/event.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
+#if defined(OS_WIN)
+#include "chrome/common/win_util.h"
+#endif
+
namespace views {
// Padding between the icon and text.
@@ -154,11 +157,11 @@ void TextButtonBorder::GetInsets(gfx::Insets* insets) const {
TextButton::TextButton(ButtonListener* listener, const std::wstring& text)
: CustomButton(listener),
+ alignment_(ALIGN_LEFT),
font_(ResourceBundle::GetSharedInstance().GetFont(
ResourceBundle::BaseFont)),
color_(kEnabledColor),
- max_width_(0),
- alignment_(ALIGN_LEFT) {
+ max_width_(0) {
SetText(text);
set_border(new TextButtonBorder);
SetAnimationDuration(kHoverAnimationDurationMs);
@@ -244,12 +247,16 @@ void TextButton::Paint(ChromeCanvas* canvas, bool for_drag) {
text_bounds.set_x(MirroredLeftPointForRect(text_bounds));
if (for_drag) {
+#if defined(OS_WIN)
+ // TODO(erg): Either port DrawStringWithHalo to linux or find an
+ // alternative here.
canvas->DrawStringWithHalo(text_, font_, color_, kHighlightColor,
text_bounds.x(),
text_bounds.y(),
text_bounds.width(),
text_bounds.height(),
l10n_util::DefaultCanvasTextAlignment());
+#endif
} else {
// Draw bevel highlight
canvas->DrawStringInt(text_,
diff --git a/chrome/views/widget/root_view.cc b/chrome/views/widget/root_view.cc
index 672a210..5e6bcc8 100644
--- a/chrome/views/widget/root_view.cc
+++ b/chrome/views/widget/root_view.cc
@@ -150,13 +150,9 @@ void RootView::ProcessPaint(ChromeCanvas* canvas) {
ScopedProcessingPaint processing_paint(&is_processing_paint_);
#endif
-#if defined(OS_WIN)
// Clip the invalid rect to our bounds. If a view is in a scrollview
// it could be a lot larger
- invalid_rect_ = gfx::Rect(GetScheduledPaintRectConstrainedToSize());
-#else
- NOTIMPLEMENTED();
-#endif
+ invalid_rect_ = GetScheduledPaintRectConstrainedToSize();
if (invalid_rect_.IsEmpty())
return;
@@ -210,6 +206,13 @@ const gfx::Rect& RootView::GetScheduledPaintRect() {
return invalid_rect_;
}
+gfx::Rect RootView::GetScheduledPaintRectConstrainedToSize() {
+ if (invalid_rect_.IsEmpty())
+ return invalid_rect_;
+
+ return invalid_rect_.Intersect(GetLocalBounds(true));
+}
+
/////////////////////////////////////////////////////////////////////////////
//
// RootView - tree
diff --git a/chrome/views/widget/root_view.h b/chrome/views/widget/root_view.h
index f7ad674..0c9f59a 100644
--- a/chrome/views/widget/root_view.h
+++ b/chrome/views/widget/root_view.h
@@ -82,10 +82,8 @@ class RootView : public View,
// Invoked by the Widget to discover what rectangle should be painted.
const gfx::Rect& GetScheduledPaintRect();
-#if defined(OS_WIN)
// Returns the region scheduled to paint clipped to the RootViews bounds.
- RECT GetScheduledPaintRectConstrainedToSize();
-#endif
+ gfx::Rect GetScheduledPaintRectConstrainedToSize();
// Tree functions
diff --git a/chrome/views/widget/root_view_gtk.cc b/chrome/views/widget/root_view_gtk.cc
index 1c7fe9c..115b37d 100644
--- a/chrome/views/widget/root_view_gtk.cc
+++ b/chrome/views/widget/root_view_gtk.cc
@@ -10,24 +10,22 @@
namespace views {
-// TODO(port): Port GetScheduledPaintRectConstrainedToSize() to not use RECT.
-
void RootView::UpdateCursor(const MouseEvent& e) {
NOTIMPLEMENTED();
}
-// TODO(port): Port OnPaint() to not use HWNDs in its public interface.
void RootView::OnPaint(GdkEventExpose* event) {
ChromeCanvasPaint canvas(event);
- canvas.FillRectInt(SK_ColorRED, 5, 5, 10, 10);
- canvas.FillRectInt(SK_ColorGREEN, 25, 5, 10, 10);
- canvas.FillRectInt(SK_ColorBLUE, 45, 5, 10, 10);
if (!canvas.isEmpty()) {
- // const PAINTSTRUCT& ps = canvas.paintStruct();
- // SchedulePaint(gfx::Rect(ps.rcPaint), false);
- if (NeedsPainting(false))
+ SchedulePaint(gfx::Rect(canvas.rectangle()), false);
+ if (NeedsPainting(false)) {
ProcessPaint(&canvas);
+
+ canvas.FillRectInt(SK_ColorRED, 5, 5, 10, 10);
+ canvas.FillRectInt(SK_ColorGREEN, 25, 5, 10, 10);
+ canvas.FillRectInt(SK_ColorBLUE, 45, 5, 10, 10);
+ }
}
}
diff --git a/chrome/views/widget/root_view_win.cc b/chrome/views/widget/root_view_win.cc
index b4641b4..89f198e 100644
--- a/chrome/views/widget/root_view_win.cc
+++ b/chrome/views/widget/root_view_win.cc
@@ -12,13 +12,6 @@
namespace views {
-RECT RootView::GetScheduledPaintRectConstrainedToSize() {
- if (invalid_rect_.IsEmpty())
- return invalid_rect_.ToRECT();
-
- return invalid_rect_.Intersect(GetLocalBounds(true)).ToRECT();
-}
-
void RootView::UpdateCursor(const MouseEvent& e) {
View *v = GetViewForPoint(e.location());
@@ -37,14 +30,15 @@ void RootView::UpdateCursor(const MouseEvent& e) {
}
void RootView::OnPaint(HWND hwnd) {
- RECT original_dirty_region = GetScheduledPaintRectConstrainedToSize();
- if (!IsRectEmpty(&original_dirty_region)) {
+ gfx::Rect original_dirty_region = GetScheduledPaintRectConstrainedToSize();
+ if (!original_dirty_region.IsEmpty()) {
// Invoke InvalidateRect so that the dirty region of the window includes the
// region we need to paint. If we didn't do this and the region didn't
// include the dirty region, ProcessPaint would incorrectly mark everything
// as clean. This can happen if a WM_PAINT is generated by the system before
// the InvokeLater schedule by RootView is processed.
- InvalidateRect(hwnd, &original_dirty_region, FALSE);
+ RECT win_version = original_dirty_region.ToRECT();
+ InvalidateRect(hwnd, &win_version, FALSE);
}
ChromeCanvasPaint canvas(hwnd);
if (!canvas.isEmpty()) {
diff --git a/chrome/views/widget/widget_gtk.cc b/chrome/views/widget/widget_gtk.cc
index 83d7766..a2a7b35 100644
--- a/chrome/views/widget/widget_gtk.cc
+++ b/chrome/views/widget/widget_gtk.cc
@@ -87,7 +87,11 @@ void WidgetGtk::SetContentsView(View* view) {
root_view_->RemoveAllChildViews(true);
root_view_->AddChildView(view);
- // TODO(erg): More windowy stuff here.
+ // TODO(erg): Terrible hack to work around lack of real sizing mechanics for
+ // now.
+ root_view_->SetBounds(0, 0, 100, 100);
+ root_view_->Layout();
+ root_view_->SchedulePaint();
NOTIMPLEMENTED();
}
@@ -143,9 +147,7 @@ bool WidgetGtk::GetAccelerator(int cmd_id, Accelerator* accelerator) {
return false;
}
-
gboolean WidgetGtk::OnPaint(GtkWidget* widget, GdkEventExpose* event) {
- // Do something here with a chrome canvas?
root_view_->OnPaint(event);
return true;
}
diff --git a/chrome/views/window/window_win.cc b/chrome/views/window/window_win.cc
index 7d2fc9a..cb7b7d6 100644
--- a/chrome/views/window/window_win.cc
+++ b/chrome/views/window/window_win.cc
@@ -742,14 +742,16 @@ void WindowWin::OnNCPaint(HRGN rgn) {
reinterpret_cast<LPARAM>(&clip_state));
RootView* root_view = GetRootView();
- CRect old_paint_region = root_view->GetScheduledPaintRectConstrainedToSize();
+ gfx::Rect old_paint_region =
+ root_view->GetScheduledPaintRectConstrainedToSize();
- if (!old_paint_region.IsRectEmpty()) {
+ if (!old_paint_region.IsEmpty()) {
// The root view has a region that needs to be painted. Include it in the
// region we're going to paint.
+ CRect old_paint_region_crect = old_paint_region.ToRECT();
CRect tmp = dirty_region;
- UnionRect(&dirty_region, &tmp, &old_paint_region);
+ UnionRect(&dirty_region, &tmp, &old_paint_region_crect);
}
root_view->SchedulePaint(gfx::Rect(dirty_region), false);