Roll src/third_party/WebKit a851be8:068171b (svn 198241:198242)
[chromium-blink-merge.git] / ui / base / page_transition_types.cc
blob0bd86f613e3a2698145d01225183cd4c6f7b8ec0
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ui/base/page_transition_types.h"
7 #include "base/logging.h"
9 namespace ui {
11 bool PageTransitionCoreTypeIs(PageTransition lhs,
12 PageTransition rhs) {
13 // Expect the rhs to be a compile time constant without qualifiers.
14 DCHECK(PageTransitionGetQualifier(rhs) == 0 &&
15 PageTransitionIsValidType(rhs));
16 return implicit_cast<int>(PageTransitionStripQualifier(lhs)) ==
17 implicit_cast<int>(PageTransitionStripQualifier(rhs));
20 PageTransition PageTransitionStripQualifier(PageTransition type) {
21 return static_cast<PageTransition>(type & ~PAGE_TRANSITION_QUALIFIER_MASK);
24 bool PageTransitionIsValidType(int32 type) {
25 PageTransition t = PageTransitionStripQualifier(
26 static_cast<PageTransition>(type));
27 return (t <= PAGE_TRANSITION_LAST_CORE);
30 PageTransition PageTransitionFromInt(int32 type) {
31 if (!PageTransitionIsValidType(type)) {
32 NOTREACHED() << "Invalid transition type " << type;
34 // Return a safe default so we don't have corrupt data in release mode.
35 return PAGE_TRANSITION_LINK;
37 return static_cast<PageTransition>(type);
40 bool PageTransitionIsMainFrame(PageTransition type) {
41 int32 t = PageTransitionStripQualifier(type);
42 return (t != PAGE_TRANSITION_AUTO_SUBFRAME &&
43 t != PAGE_TRANSITION_MANUAL_SUBFRAME);
46 bool PageTransitionIsRedirect(PageTransition type) {
47 return (type & PAGE_TRANSITION_IS_REDIRECT_MASK) != 0;
50 bool PageTransitionIsNewNavigation(PageTransition type) {
51 return (type & PAGE_TRANSITION_FORWARD_BACK) == 0 &&
52 !PageTransitionCoreTypeIs(type, PAGE_TRANSITION_RELOAD);
55 int32 PageTransitionGetQualifier(PageTransition type) {
56 return type & PAGE_TRANSITION_QUALIFIER_MASK;
59 bool PageTransitionIsWebTriggerable(PageTransition type) {
60 int32 t = PageTransitionStripQualifier(type);
61 switch (t) {
62 case PAGE_TRANSITION_LINK:
63 case PAGE_TRANSITION_AUTO_SUBFRAME:
64 case PAGE_TRANSITION_MANUAL_SUBFRAME:
65 case PAGE_TRANSITION_FORM_SUBMIT:
66 return true;
68 return false;
71 const char* PageTransitionGetCoreTransitionString(PageTransition type) {
72 int32 t = PageTransitionStripQualifier(type);
73 switch (t) {
74 case PAGE_TRANSITION_LINK: return "link";
75 case PAGE_TRANSITION_TYPED: return "typed";
76 case PAGE_TRANSITION_AUTO_BOOKMARK: return "auto_bookmark";
77 case PAGE_TRANSITION_AUTO_SUBFRAME: return "auto_subframe";
78 case PAGE_TRANSITION_MANUAL_SUBFRAME: return "manual_subframe";
79 case PAGE_TRANSITION_GENERATED: return "generated";
80 case PAGE_TRANSITION_AUTO_TOPLEVEL: return "auto_toplevel";
81 case PAGE_TRANSITION_FORM_SUBMIT: return "form_submit";
82 case PAGE_TRANSITION_RELOAD: return "reload";
83 case PAGE_TRANSITION_KEYWORD: return "keyword";
84 case PAGE_TRANSITION_KEYWORD_GENERATED: return "keyword_generated";
86 return NULL;
89 } // namespace ui