I'm trying to create a simple dialog box following the exam at
http://dev.chromium.org/developers/design-documents/views-windowing.
Note that I'm using views as in a standalone app (I'm not embedding
this dialog in Chromium).
I've added 2 views::Textfields to WindowView, but I can't seem to tab
between them. When I press the tab key, it simply inserts a tab into
the editbox.
Here is what I have:
<snip>
#pragma once
#include "views/controls/textfield/textfield.h"
#include "views/view.h"
#include "views/window/dialog_delegate.h"
namespace views {
class Label;
class Textfield;
}
class WindowView : public views::View,
public views::DialogDelegate,
public views::Textfield::Controller {
public:
WindowView();
~WindowView();
// Overridden from views::View:
virtual void Paint(gfx::Canvas* canvas);
virtual void Layout();
virtual gfx::Size GetPreferredSize();
// Overridden from views::DialogDelegate:
virtual std::wstring GetWindowTitle() const { return L"Demo"; }
virtual bool CanResize() const { return true; }
virtual bool CanMaximize() const { return true; }
virtual views::View* GetContentsView() { return this; }
virtual int GetDialogButtons() const { return
MessageBoxFlags::DIALOGBUTTON_OK; }
// Return the view that you want to have initially focused
virtual views::View* GetInitiallyFocusedView();
private:
// Overridden from views::Textfield::Controller:
virtual void ContentsChanged(views::Textfield* sender,
const std::wstring& new_contents);
virtual bool HandleKeystroke(views::Textfield* sender,
const views::Textfield::Keystroke&
keystroke);
views::Label* label1_;
views::Textfield* textbox1_;
views::Label* label2_;
views::Textfield* textbox2_;
DISALLOW_COPY_AND_ASSIGN(WindowView);
};
</snip>
<snip>
#include "kreofusion/misc/context_menu_demo/window_view.h"
#include "app/gfx/canvas.h"
#include "base/message_loop.h"
#include "views/controls/label.h"
#include "views/standard_layout.h"
#include "views/widget/root_view.h"
WindowView::WindowView()
: label1_(new views::Label(L"Textbox 1")),
textbox1_(new views::Textfield()),
label2_(new views::Label(L"Textbox 2")),
textbox2_(new views::Textfield()) {
textbox1_->SetController(this);
textbox2_->SetController(this);
AddChildView(label1_);
AddChildView(textbox1_);
AddChildView(label2_);
AddChildView(textbox2_);
}
WindowView::~WindowView() {
MessageLoop::current()->Quit();
}
void WindowView::Paint(gfx::Canvas* canvas) {
views::View::Paint(canvas);
}
void WindowView::Layout() {
const gfx::Rect lb = bounds();
if (lb.IsEmpty())
return;
gfx::Size ps = label1_->GetPreferredSize();
int y = kButtonVEdgeMargin;
label1_->SetBounds(kButtonHEdgeMargin, y, ps.width(), ps.height());
y += ps.height() + kRelatedControlSmallVerticalSpacing;
ps = textbox1_->GetPreferredSize();
textbox1_->SetBounds(kButtonHEdgeMargin, y, lb.width() -
2*kButtonHEdgeMargin, ps.height());
y += ps.height() + kUnrelatedControlVerticalSpacing;
ps = label2_->GetPreferredSize();
label2_->SetBounds(kButtonHEdgeMargin, y, ps.width(), ps.height());
y += ps.height() + kRelatedControlSmallVerticalSpacing;
ps = textbox2_->GetPreferredSize();
textbox2_->SetBounds(kButtonHEdgeMargin, y, lb.width() -
2*kButtonHEdgeMargin, ps.height());
}
gfx::Size WindowView::GetPreferredSize() {
gfx::Size ps = label1_->GetPreferredSize();
ps.set_width(ps.width() + 200);
ps.set_height(ps.height() + 200);
return ps;
}
views::View* WindowView::GetInitiallyFocusedView() {
return textbox2_;
}
////////////////////////////////////////////////////////////////////////////////
// WindowView, private:
void WindowView::ContentsChanged(views::Textfield* sender,
const std::wstring& new_contents)
{
}
bool WindowView::HandleKeystroke(views::Textfield* sender,
const views::Textfield::Keystroke&
keystroke) {
return false;
}
</snip>
What am I doing wrong?
--~--~---------~--~----~------------~-------~--~----~
Chromium Developers mailing list: [email protected]
View archives, change email options, or unsubscribe:
http://groups.google.com/group/chromium-dev
-~----------~----~----~----~------~----~------~--~---